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

JavaScript09

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>

<!DOCTYPE html>

<html>

<head>

  <title>test page</title>

  <meta http-equiv="content-type" content="text/htmlcharset=utf-8">

</head>

<body>

<input type="checkbox" name="sports[]" value="0">足球<br>

<input type="checkbox" name="sports[]" value="10">篮球<br>

<input type="checkbox" name="sports[]" value="20">排球<br>

<input type="checkbox" name="sports[]" value="30">乒乓球<br>

<input type="checkbox" name="sports[]" value="40">羽毛球<br>

<input type="checkbox" name="sports[]" value="50">橄榄球<br>

<input type="checkbox" name="sports[]" value="60">冰球<br>

<input type="checkbox" name="sports[]" value="70">曲棍球<br>

<input type="checkbox" name="sports[]" value="80">同求<br><br>

<input type="checkbox" id="chkAll" onclick="chkAll(this)">全选

<script type="text/javascript">

  var objs = document.getElementsByName('sports[]')

  function chkAll(obj){

    for (var i = objs.length - 1 i >= 0 i--) {

      objs[i].checked = obj.checked

    }

  }

</script>

</body>

</html>