I want to send a url to an iframe using an ajax call, but I'm not sure if this is possible.
Here's what I have so far:
<script>
$(document).ready(function() {
$('.clickme').click(function() {
var id = $(this).attr(id);
// Need to send the URL below to the iframe
// http://www.example.com/?开发者_运维技巧list_id=id
});
});
</script>
<iframe name="get_data"></iframe>
<div class="clickme" id="3453">Click Here</div>
Any suggestions?
$("iframe[name='get_data']").prop("src", "http://www.example.com/?list_id=" + id);
$(document).ready(function() {
$('.clickme').click(function() {
var id = $(this).attr(id);
$('iframe[name="get_data"]').attr('src', 'http://www.example.com/?list_id=' + id);
});
});
if you are using jquery 1.6
or higher use prop
(as stated by Andrew Whitaker )
$("iframe[name='get_data']").prop("src", "http://www.example.com/?list_id=" + id);
$('iframe').attr('src', url);
You probably want a better selector.
You should be able to just get a handle on the iframe
and set its src
attribute:
$('iframe[name="get_data"]').attr('src', 'http://www.example.com/?list_id=' + id);
精彩评论