jquery----绑定事件
jquery 绑定事件
添加绑定事件
// $(".btn").on('click',function () { #事件委派
// $(".c1").toggleClass('c2')
// });
$(".btn").click(function () {
$(".c1").toggleClass('c2')
})
解除绑定事件
$("button).unbind(); //移除所有的绑定事件
js 中的绑定事件
1、在标签中直接添加 onclick=fun() 事件, script中写函数
2、
<script defer>
function clickHandler() {
alert("onclick attribute in html");
}
function clickHandler2(e) {
alert(e.target.innerHTML);
}
document.getElementById("jsOnClick").onclick = clickHandler2;
document.getElementById("addEventListener").addEventListener("click",clickHandler2); #事件委派
</script>
补充
return '<button onclick="detatil_show(\''+"xxx"+'\')"><button>'
return '<button onclick="detatil_show('+"'"+"xxxx"+"'"+')"><button>' 两个效果一样,外面好像一定要用单引号括起来
将当前对象传入事件中
<select onchange="onItatingChange($(this))"/>
function onItatingChange(v){
if(!v.val()){
v.attr("selectedValue","")
}
}

浙公网安备 33010602011771号