使用内联javascript加载jquery [英] jquery load with inline javascript
问题描述
我正在使用jquery load来获取不同页面上的div并将其插入到我的页面中。
这样的事情:
I am using jquery load to get a div on a different page and insert it into my page. somthing like this:
$('#mydiv').load("/Pages/grid2.aspx" + " #otherpagediv");
在另一页的div中,div中有javascript。 javascript没有出现,只有html内容。有没有办法在指定的div中获取所有内容?
In the div on the other page, there is javascript in the div. The javascript is not coming across, only the html content. Is there a way to get everything in the specified div?
推荐答案
这有效:
$.get( '/Pages/grid2.aspx', function ( data ) {
$( '#mydiv' ).html( $( '<div></div>' ).html( data ).find( '#otherpagediv' ).clone() );
});
现场演示: http://jsfiddle.net/FRbnD/4/show/light/
了解演示,查看构成它的两个页面的源代码:
演示的源代码: http:// jsfiddle .net / FRbnD / 4 /
其他页面的源代码: http:// jsfiddle.net/MWkSj/1/
To understand the demo, view the source code of both pages that comprise it:
Source code of the demo: http://jsfiddle.net/FRbnD/4/
Source code of the "other page": http://jsfiddle.net/MWkSj/1/
想法是通过 $来获取其他页面。获取
请求,然后找到 #otherpagediv
和克隆。然后,将克隆附加到 #mydiv
。如果将克隆插入DOM,并且该克隆包含SCRIPT元素,则将执行该脚本。
The idea is to retrieve the other page via a $.get
request, and then find the #otherpagediv
and clone it. You then append the clone to the #mydiv
. If you insert a clone to the DOM and if that clone contains a SCRIPT element, that script will be executed.
这篇关于使用内联javascript加载jquery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!