JS 如何实现按下Esc按键全选文本框中的文本内容?

JavaScript014

JS 如何实现按下Esc按键全选文本框中的文本内容?,第1张

<!DOCTYPE html>

<html>

<head>

<title></title>

</head>

<body>

<div>文本框:</div>

<textarea>按下ESC选中我</textarea>

<script src="jquery.min.js" ></script>

<script type="text/javascript">

function hotkey()

{

var a=window.event.keyCode

if(a==27)

{

$('textarea').select()

}

}

// 初始化加载

$(document).ready(function () {

document.onkeydown = hotkey

})

</script>

</body>

</html>

有如下的文本框:

<input name="jbxue_form" id="jbxue_form" value="内容" /> <script>

//JS选中文本框中内容

document.getElementById("jbxue_form").focus()

document.getElementById("jbxue_form").select()

//jquery选中文本框中内容

$("#jbxue_form").focus()

$("#jbxue_form").select()

</script>