<html>
<div class="button">
<input type="button" onclick="method1();" id="1" value="Button1"/>
</div>
<div class="button">
<input type="button" onclick="method2();" id="2" value="Button2"/>
</div>
</html>
在不修改Html的情况下,我可以将两个按钮合并为一个按钮吗?当单击该按钮时,是否可以调用这两个方法?这可以用 Javascript/JQuery 完成吗?如果是这样,你会怎么做?
换句话说,我可以在不更改 html 的情况下隐藏一个按钮并触发两种方法吗?
最佳答案
$("#1, #2").click(function(){
method1();
method2();
return false;
});
编辑
根据 Yardboy 的评论,OP 可能需要这个
$(function(){
$("#2").parent().hide();
$("#1").click(function(){
method1();
method2();
return false;
});
});
关于javascript - 我可以使用类似 javascript 的东西组合两个 html 按钮及其 onclick 方法吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7366700/