关于jQuery事件的问题(Question on jQuery event)

编程入门 行业动态 更新时间:2024-10-27 02:25:18
关于jQuery事件的问题(Question on jQuery event)

如果我有如下代码;

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 } }

更多推荐

本文发布于:2023-08-04 22:17:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1423185.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:事件   jQuery   event   Question

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!