如何将Jquery load()链接发送到iframe

时间:2017-09-28 16:18:48

标签: javascript jquery ajax iframe ahah

我遇到AHAH Jquery方法load()的问题。我想点击表格中的链接后

<table class="table table-hover" style="background: white;">
<tbody>
<tr>
<td><a title="Dominikana" href="../../oferty-hotelowe/tajlandia"><img src="../../upload/getbyid/175094/Thailand-Flag-icon (1).png" alt="Dominikana"></a></td>
<td><a title="Dominikana" href="../../oferty-hotelowe/tajlandia">Tajlandia</a></td>
<td class="arrow"><a title="Dominikana" href="../../oferty-hotelowe/tajlandia">&gt;</a></td>
</tr>

链接应该在iframe中打开,但它不起作用,只会弹出警报。

<iframe id="64704528" src="" width="100%" height="720"></iframe>


var $widget = $(".table-hover");

$widget.find("a").on('click', function(e) {
    e.preventDefault; 

    var $frame = $("iframe#64704528");

    $frame.load("http://comfort31.traffics-ibe.com/tibet.php?target=%2Fuslugi%2Fzakwaterowanie%2F&amp;ixp=hotel&amp;typ=H&amp;cfg=0080017030000000&amp;stp=2&amp;rmask=1&amp;hmask=2&amp;tps=t5&amp;xP=0000%2B0000&amp;lng=pl&amp;dsi=ALLE&amp;opi=&amp;htn=&amp;vnd = 20.05.2011 &amp; BSD = 20 czerwca 2011 i EPC = 2-enc = UTF-8-NTC = 1", function() {
  alert( "Load was performed." ); 
    });
  });  

1 个答案:

答案 0 :(得分:-1)

.load()用于设置元素的HTML,但不能将HTML直接放入iframe。您应该将src设置为指向网址。

$frame.attr("src", "http://comfort31.traffics-ibe.com/tibet.php?target=%2Fuslugi%2Fzakwaterowanie%2F&amp;ixp=hotel&amp;typ=H&amp;cfg=0080017030000000&amp;stp=2&amp;rmask=1&amp;hmask=2&amp;tps=t5&amp;xP=0000%2B0000&amp;lng=pl&amp;dsi=ALLE&amp;opi=&amp;htn=&amp;vnd = 20.05.2011 &amp; BSD = 20 czerwca 2011 i EPC = 2-enc = UTF-8-NTC = 1")
    .on("load", function() {
        alert("Load was performed.");
});