jquery怎么移除onclick属性

使用jquery移除onclick属性的方法:1.新建html项目,引入jquery;2.创建div标签,绑定onclick点击事件;3.通过标签名获取标签对象,使用removeAttr()方法删除onclick属性;

具体步骤如下:

1.首先,新建一个html项目,并在项目中引入jquery;


<script type="text/javascript" src="/static/jquery-2.1.4.min.js"></script>

2.引入jquery后,在项目中创建一个div标签,并绑定一个onclick点击事件;


<div onClick="set()"></div>

3.div标签创建好后,在事件中通过标签名获取标签对象,在使用removeAttr()方法即可删除onclick属性;

$(document).ready(function(){

$("div").click(function(){

$(this).removeAttr("onclick");

});

});


相关扩展:

1)使用attr()方法设置onclick属性

$("div").attr("onclick","set();");


Both comments and pings are currently closed.

Comments are closed.

Powered by KingAbc | 粤ICP备16106647号-2 | Loading Time‌ 0.293