2012-04-19 60 views
3

我想另一个网页的HTML内容,所以我用下面的jQuery的获得()函数不能使用jQuery获得()来获取HTML内容

$.get("chk_vga.aspx", function(data) { 
    alert($('#vga').html()); 
}); 

在“chk_vga.aspx”页面,它只有一个值

<html> 
    <body> 
     <div id="vga">F</div> 
    </body> 
</html> 

我的jquery函数如何获得“F”值?

+0

增加了两个选项,请查看我的答案;) – Luis 2012-04-19 02:29:25

回答

1

要访问您需要将其添加到一个元素的内容。

$.get("chk_vga.aspx", function(data) { 
    var foo = jQuery("<div></div>").html(data).find("#vga").html(); 
    alert(foo); 
}); 
+0

它的工作原理。非常感谢。 – 2012-04-19 02:34:16

3
.load('chk_vga.aspx #vga', function(data) { 
    alert(data); 
}); 
+0

这将让他的整个HTML页面,我相信。我想他只是想获得“F”。 – wkm 2012-04-19 02:19:23

+0

不,它不会,$ .get'的'url'参数包含'id = vga'的选择器。 – Gabe 2012-04-19 02:21:24

+0

啊我没有注意到#vga选择器。我的错。 – wkm 2012-04-19 02:21:49

1

这里你正在做的是alert()#vga父母的内部HTML。如果您使用此代码,则会在远程页面上获得#vga div的#vga内部HTML。

$.get('chk_vga.aspx', function(data) { 
    alert(data.match(/id="vga">(.[^\"]*)<\/div>/i)[1]);    
}); 

OR

$.get('chk_vga.aspx', function(data) { 
    alert(data); 
}); 
0
$("#aSolucoes").click(function(e) { 
      e.preventDefault(); 
      mostrarCarregando(); 
      $("#divModal").load('Consulting.aspx', aposCarregamento); 

     }); 

     function mostrarCarregando() { 
      $("#divModal").css('display', 'block').fadeIn(1000); 
     }; 

     function aposCarregamento() { 
      $("#divModal").reveal({ 
       animation: 'fadeAndPop',     //fade, fadeAndPop, none 
       animationspeed: 300,      //how fast animtions are 
       closeonbackgroundclick: true,    //if you click background will modal close? 
       dismissmodalclass: 'close-reveal-modal' //the class of a button or element that will close an open modal 
      }); 
     };