[英]how to prevent to calling another function in JS?
function datePicker(event)
{
//do something`enter code here`
}
document.onclick=function() {
//do something
}
When I call datePicker() function I want to prevent the calling second method . 当我调用datePicker()函数时,我想防止调用第二个方法。 How to do that ? 怎么做 ?
Use event.stopPropagation()
to stop the event bubbling up to the document
click listener: 使用event.stopPropagation()
可以停止事件冒泡直至document
单击侦听器:
function datePicker(event)
{
event.stopPropagation();
}
You can also use event.stopImmediatePropagation()
to stop sibling elements receiving the event too, if necessary: jquery: stopPropagation vs stopImmediatePropagation 您也可以使用event.stopImmediatePropagation()
来停止接收事件的兄弟元素,如有必要: jquery:stopPropagation vs stopImmediatePropagation
jQuery Example with IE8 catered for: http://jsfiddle.net/kHT2A/2/ 带有IE8的jQuery示例可满足以下需求: http : //jsfiddle.net/kHT2A/2/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.