在jQuery中单击带有按钮 [英] on Click with button in jQuery
本文介绍了在jQuery中单击带有按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个单击特定元素时会被调用的函数
I have a function that is being called when a particular element is clicked
$(".clickThis").click(function() {
}
我想添加一个HTML按钮,当单击它时也调用此函数
I would like to add an HTML button and when it is clicked also call this function
<input type="button" value="Cancel">
我是否需要添加一个类名,或者除了元素外,是否有一种针对它的方法?
Do I need to add a class name to it or is there a way to target it but element?
我可以添加第二个触发器来调用我的函数吗?
Can I add second trigger to call my function like this:
$(".clickThis, button").click(function() {
推荐答案
添加ID会更好,更快.像这样:
Adding an ID would be better and fastest. Something like:
<input id="cancelButton" type="button" value="Cancel">
然后
$(".clickThis, #cancelButton").click(function(){
//Your Code here..
});
如果要在不更改HTML的情况下调用它,请尝试以下操作:
If you want to call it with out changing the HTML, try this:
$(".clickThis, :button[value='Cancel']").click(function(){
//Your Code here..
});
这篇关于在jQuery中单击带有按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文