如果我有如下代码;
if (x == "0") { $("input:checkbox").parent().mouseover(function () { //Some code } }我的问题是代码是否会在每次鼠标悬停时执行或者它会首先检查x ==“0”条件然后触发?
换句话说,是$("input:checkbox").parent().mouseover()代码类似于使用bind()或live()函数获得的代码(每次在该事件上被触发)和“x”的封闭条件无关紧要?
我们有什么方法可以将事件与“x”条件联系起来,例如只有当x为真时限制它的范围?
我不确定我的问题是否真的有效。 但如果你能澄清那将是非常好的。
If I have a code like the following;
if (x == "0") { $("input:checkbox").parent().mouseover(function () { //Some code } }My question is will the code get executed on each mouseover OR it will first check the x == "0" condition and then fire ?
In other words, is the $("input:checkbox").parent().mouseover() code similar to what one would get with a bind() or live() function (which gets fired every time on that event) and the enclosing condition of "x" won't matter ?
Is there any way by which we can link the event with the "x" condition like limiting it's scope only if x is true?
I am not really sure if my question is really valid. But it would be really great if you could clarify.
最满意答案
我的问题是代码是否会在每次鼠标悬停时执行或者它会首先检查x ==“0”条件然后触发?
如果在编写此代码时x ==“0”,它将在每次鼠标悬停时执行。
如果你只想执行一段代码,如果x ==“0”,请尝试
var x = "0"; // or any other value. $("input:checkbox").parent().mouseover(function () { if(x == "0") { // code goes here } }My question is will the code get executed on each mouseover OR it will first check the x == "0" condition and then fire ?
It'll get executed on each mouseover, if x == "0" at the point you have written this code.
If you want to only execute a piece of code if x == "0", try
var x = "0"; // or any other value. $("input:checkbox").parent().mouseover(function () { if(x == "0") { // code goes here } }更多推荐
发布评论