js 中的onselect 与jQuery中的select 事件的用法

 1、   jQuery 的用法如下:

 

<!DOCTYPE html>
<html>
<head>
  <style>
  p { color:blue; }
  div { color:red; }
  </style>
  <script src="http://code.jquery.com/jquery-latest.min.js"></script>
</head>
<body>
  <p>

    Click and drag the mouse to select text in the inputs.
  </p>
  <input type="text" value="Some text" />
  <input type="text" value="to test on" />

  <div></div>
<script>
    $("input").select( function () {
      alert($(this).val());
    });
</script>

</body>
</html>

 

 

 

 

2、javaScript 的用法如下:

 

<!DOCTYPE html>
<html>
<head>

</head>

<script>
function myOnSelect(c)
{
    alert(c.value);
}
</script>

<body>
  <p>

    Click and drag the mouse to select text in the inputs.
  </p>
  <input type="text" value="Some text"  onselect="myOnSelect(this);"/>
  <input type="text" value="to test on" onselect="myOnSelect(this);"/>

</body>
</html>

你可能感兴趣的:(jquery)