Can I combine two html buttons and their onclick methods using something like javascript?
<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>
Without having to modify the Html, can I combine the two buttons into one button? And when that button is clicked, can both the methods 开发者_如何学运维be called? Can this be done with Javascript/JQuery? If so, how would you do it?
In other words, can I hide one button and fire both methods without changing the html.
$("#1, #2").click(function(){
method1();
method2();
return false;
});
EDIT
Based on Yardboy's comment the OP might want this instead
$(function(){
$("#2").parent().hide();
$("#1").click(function(){
method1();
method2();
return false;
});
});
You can add both method calls to one onclick attribute.
<div class="button">
<input type="button" onclick="method1();method2();" id="1" value="Button1"/>
</div>
精彩评论