gpt4 book ai didi

javascript - jQuery 事件触发

转载 作者:行者123 更新时间:2023-11-30 09:03:29 25 4
gpt4 key购买 nike

如果我有如下代码;

if (x == "0")
{
$("input:checkbox").parent().mouseover(function () {
//Some code
}
}

我的问题是代码会在每次 mouseover 时执行,还是会先检查 x == "0" 条件然后触发?

换句话说,$("input:checkbox").parent().mouseover() 代码是否类似于使用 bind()live() 函数(每次发生该事件时都会触发)和“x”的封闭条件无关紧要?

有什么方法可以将事件与“x”条件联系起来,比如仅在 x 为真时限制事件的范围?

我不确定我的问题是否真的有效。但如果您能澄清一下,那就太好了。

最佳答案

My question is will the code get executed on each mouseover OR it will first check the x == "0" condition and then fire ?

如果在您编写这段代码时 x == "0",它将在每次鼠标悬停时执行。

如果你只想在x == "0"时执行一段代码,试试

 var x = "0"; // or any other value.
$("input:checkbox").parent().mouseover(function () {
if(x == "0") {
// code goes here
}
}

关于javascript - jQuery 事件触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7175422/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com