【jquery】怎么用js调用标签的onclick事件

rt!

给你一个示例:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"> 
<title>菜鸟教程(runoob.com)</title> 
<script src="https://cdn.bootcss.com/jquery/2.0.0/jquery.min.js">
</script>
<script>
$(document).ready(function(){
  $("button").click(function(){
    $("p").hide();
  });
});
</script>
</head>

<body>
<h2>这是一个标题</h2>
<p>这是一个段落。</p>
<p>这是另一个段落。</p>
<button>点我</button>
</body>
</html>

温馨提示:答案为网友推荐,仅供参考
第1个回答  2013-04-03
在每一个匹配元素的click事件中绑定一个处理函数。点击事件会在你的指针设备的按钮在元素上单击时触发。单击的定义是在屏幕的同一点触发了mousedown和mouseup.常用的事件有如下的 mousedownmouseupclickBinds a function to the click event of each matched element.The click event fires when the pointing device button is clicked over an element. A click is defined as a mousedown and mouseup over the same screen location. The sequence of these events is: mousedownmouseupclick返回值jQuery参数fn (Function) : 绑定到click事件的函数示例将页面内所有段落点击后隐藏。 jQuery 代码:$("p").click( function () { $(this).hide(); });
第2个回答  2017-08-09
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title></title>
</head>
<body>
<script type="text/javascript" src="jquery-1.7.1.min.js"></script>
<div>
    <input type="text" value="" name="username" class="username" />
    <input type="button" value="点击获取输入框的值"  name="sub" onclick="getData();" />
    <script type="text/javascript">
        function getData(){
            var username = $.trim($(".username").val());
            alert(username);
        }
    </script>
</div>
</body>
</html>

第3个回答  2017-08-11

推荐这么写

$('xxx').on('click',function(){
    //逻辑处理
})

第4个回答  2013-04-03
<input type="button" class="wel" value="欢迎" id="welcome">
$("#welcome").bind("click",function(){alert('您点击我了!');});