I have button A
with
onclick = "alert(1);"
And button B
.
How to do, when I click on button B
, it should call event on button A
?
click B -> eventB -> eventA
I have button A
with
onclick = "alert(1);"
And button B
.
How to do, when I click on button B
, it should call event on button A
?
click B -> eventB -> eventA
Share Improve this question edited Apr 29, 2015 at 21:13 000 27.3k10 gold badges74 silver badges103 bronze badges asked Feb 9, 2011 at 2:20 ChameronChameron 2,9848 gold badges36 silver badges46 bronze badges 02 Answers
Reset to default 5HTML:
<button id="buttonA"> Button A </button>
<button id="buttonB"> Button B </button>
JavaScript:
var a = g('buttonA'),
b = g('buttonB');
function g(s) { return document.getElementById(s); }
a.onclick = function() {
alert('Button A clicked!');
};
b.onclick = function() {
alert('Button B clicked!');
a.click();
}
Live demo: http://jsfiddle/TaPWr/1/
Update:
If the Button B is inside an IFRAME then use the top
object to reference the window object of the "parent" page. The IFRAME code would be like so:
var b = document.getElementById('buttonB');
b.onclick = function() {
alert('Button B clicked!');
top.document.getElementById('buttonA').click();
}
onclick="document.getElementById('buttonAId').click();"
put that on button B
update: if button A is in the form that has iframe where button A is:
onclick="parent.document.getElementById('buttonAId').click();"
assuming both frames are served from the same domain
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745213333a4616972.html
评论列表(0条)