trigger函数的应用

<html>
<head>
<script type="text/javascript" src="/jquery/jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
  $("input").select(function(){
    $("input").after("文本被选中!");//在input后增加“文字被选中!”字样
  });
  $("button").click(function(){
    $("input").trigger("select");//选中input中的内容
  });
});
</script>
</head>
<body>
<input type="text" name="FirstName" value="Hello World" />
<br />
<button>激活 input 域的 select 事件</button>
</body>
</html>

  trigger() 方法触发被选元素的指定事件类型。规定被选元素要触发的事件。

$(selector).trigger(event,[param1,param2,...])
posted @ 2017-08-09 09:27  米修^~^  阅读(247)  评论(0编辑  收藏  举报