admin管理员组文章数量:1221949
I have a list of links that open in an iframe, like:
<ul id="frameTrigger">
<li><a target="iframe1" href="aaa.html"><img src="aaa.jpg"></a></li>
<li><a target="iframe1" href="bbb.html"><img src="bbb.jpg"></a></li>
<li><a target="iframe1" href="ccc.html"><img src="ccc.jpg"></a></li>
</ul>
I need to update another div after the link is clicked. Specifically, I need to call a function that checks the frame's src
attribute and update the div. If I do a:
$("#frameTrigger a").click(function() {
var iframe = $("iframe[name=iframe1]").get(0);
console.log(iframe.contentWindow.location.href);
// the problem here is that that the iframe.window.location will
// change AFTER this function returns
});
I do not get what is expected.
I have a list of links that open in an iframe, like:
<ul id="frameTrigger">
<li><a target="iframe1" href="aaa.html"><img src="aaa.jpg"></a></li>
<li><a target="iframe1" href="bbb.html"><img src="bbb.jpg"></a></li>
<li><a target="iframe1" href="ccc.html"><img src="ccc.jpg"></a></li>
</ul>
I need to update another div after the link is clicked. Specifically, I need to call a function that checks the frame's src
attribute and update the div. If I do a:
$("#frameTrigger a").click(function() {
var iframe = $("iframe[name=iframe1]").get(0);
console.log(iframe.contentWindow.location.href);
// the problem here is that that the iframe.window.location will
// change AFTER this function returns
});
I do not get what is expected.
Share Improve this question edited Nov 26, 2022 at 18:45 Brian Tompsett - 汤莱恩 5,88372 gold badges61 silver badges133 bronze badges asked Apr 16, 2011 at 8:09 Salman ArshadSalman Arshad 272k84 gold badges442 silver badges533 bronze badges 4 |3 Answers
Reset to default 9I'm guessing you get the old value instead of the new one? You may want to wrap your function in a setTimeout
of 1ms to allow the update to go through.
$("#frameTrigger a").click(function(){
console.log( $(this).attr("href") );
});
You need the first selector to work on clicks for the links. Also, I think you had the syntax for console.log incorrect (though I have never used it). I changed it so when you click on a link it logs the href attribute of the link. Hope this helps.
If you're having trouble with the entire click functionality completing when calling the click via jQuery .click() - I know it's not ideal, but - perhaps you should just have jQuery explicitly complete the sequence that should be executed when clicked. Something like:
$("#someElement").bind('click', function(event) {
event.preventDefault();
$($("#frameTrigger a:eq(1)").attr('target')).attr('src', $("#frameTrigger a:eq(1)").attr('href'));
});
本文标签: javascriptjQuery quotafterclickquot eventStack Overflow
版权声明:本文标题:javascript - jQuery "after-click" event - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1739283210a2156341.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
$("#frameTrigger")
you are missing # ... just in case – Rafay Commented Apr 16, 2011 at 8:14