当我单击文本框时,如何查找调用哪个jQuery事件?

时间:2013-05-22 14:34:51

标签: jquery html events dom

我继承了一个软件,在其中我无法弄清楚jQuery中click事件的位置。

当用户单击表单上的文本框时,它旁边的复选框使用我似乎无法找到的jquery调用切换。我搜索了同事.js文件,而且我找不到它。

我是否可以使用任何工具,提示或技巧来查找触发点击事件的内容,以便我可以更改/停用它?

以下是表单周围标记的示例:

<li>
    <input type="checkbox" name="checkbox_other1" id="checkbox_other1" value="checkbox_other1" />
    <label for="checkbox_other1">Other <input type="text" id="textfield_other1" name="textfield_other1" size="35" maxlength="35">.</label>
</li>
<li>
    <input type="checkbox" name="checkbox_other2" id="checkbox_other2" value="checkbox_other2" />
    <label for="checkbox_other2">Other <label for="checkbox_other2">
        <input type="text" id="textfield_other2" name="textfield_other2" size="35" maxlength="35">.
    </label>
</li>

感谢。

所以我觉得我的想法太高了。导致问题的不是jquery / javascript,而是将文本字段附加到复选框的标签标签。感谢所有的帮助。

3 个答案:

答案 0 :(得分:4)

Visual Event是在网页上查找活动的非常方便的工具。

您可以将其加入书签,然后在任何网页上使用。

也可以chrome extension

答案 1 :(得分:0)

不知道为什么这让我花了很长时间才意识到,但你可以直接打印onclick处理程序:

<html>
    <head>
        <script>
            function thisiswhyimhot()
            {
                alert("this is why you're not");
            }

            function mybodyisready()
            {
                alert(document.getElementById("hottestdivever").onclick);
            }
        </script>
    </head>
    <body onload="mybodyisready()">
        <div id="hottestdivever" onclick="thisiswhyimhot()"></div>
    </body>
</html>

将使用以下内容弹出警告:

function onclick(event) {
thisiswhyimhot()
}

如果使用JQuery设置处理程序,它将以稍微不同的方式存储:

alert(jQuery._data(document.getElementById("hottestdivever"), "events").click[0].handler);

这将为您提供在JS中搜索的内容。

最后,JSFiddle演示了vanilla Javascript和jQuery方法。

在其他新闻中,我有一个新的函数名称,用于我从现在开始编写的每个正文直到时间结束 ...

答案 2 :(得分:-2)

尝试event.type

$("#test").on("click change", function(event){
    alert(event.type + " is fired");
});