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

rt!... rt! 展开
 我来答
不要欺负小朋友
推荐于2017-08-11 · TA获得超过226个赞
知道小有建树答主
回答量:236
采纳率:0%
帮助的人:108万
展开全部

给你一个示例:

<!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>
匿名用户
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(); });
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
飞离地平线Ch
2017-08-09 · TA获得超过194个赞
知道小有建树答主
回答量:257
采纳率:71%
帮助的人:70.3万
展开全部
<!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>
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
百度网友5b2d7dc
2017-08-11 · 知道合伙人软件行家
百度网友5b2d7dc
知道合伙人软件行家
采纳数:46 获赞数:198
福建省中秀网络科技有限公司核心技术工程师

向TA提问 私信TA
展开全部

推荐这么写

$('xxx').on('click',function(){
    //逻辑处理
})
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
匿名用户
2013-04-03
展开全部
<input type="button" class="wel" value="欢迎" id="welcome">
$("#welcome").bind("click",function(){alert('您点击我了!');});
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(9)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式