JQuery的html的()方法和外部脚本 [英] JQuery .html() method and external scripts

查看:192
本文介绍了JQuery的html的()方法和外部脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我加载,使用jQuery的 AJAX()方式,既​​HTML和JavaScript code外部页面:

i'm loading, using the JQuery ajax() method, an external page with both html and javascript code:

<script type="text/javascript" src="myfile.js"></script>
<p>This is some HTML</p>
<script type="text/javascript">
     alert("This is inline JS");
</script>

和设置结果到一个div元素,使用 HTML()方式。

and setting the results into a div element, using the html() method.

虽然在html()方法正确地评估直列JS code,它不下载和评估外部JS文件myfile.js

While the html() method properly evaluates the inline JS code, it doesn't download and evaluate the external JS file "myfile.js".

任何提示此问题?

推荐答案

如果你控制了外部网页,你可以改变这种

If you control the external page you could change this

<script type="text/javascript" src="myfile.js"></script>

<script type="text/javascript" src="http://host/path/myfile.js"></script>


演示: http://jsbin.com/ucomu3/3 负载的 http://jsbin.com/otopi/3 通过 $ AJAX 和通过 HTML设置返回的数据() 的http:// jsbin。 COM / otopi / 3 包含嵌入式脚本标记,一个用在SRC属性指向一个完整合格的URL http://jsbin.com/uyova3


Demo: http://jsbin.com/ucomu3/3 loads http://jsbin.com/otopi/3 via $.ajax and sets the returned data via html() http://jsbin.com/otopi/3 contains an inline script tag and one with a full qualified URL in the src-attribute which points to http://jsbin.com/uyova3

所以,如果你打开​​ http://jsbin.com/ucomu3/3 你看这是一些HTML和两个警报其中说:我是外部本地JS和这是内联JS

So if you open http://jsbin.com/ucomu3/3 you see "This is some HTML" and two alerts which say "I'm the external local js" and "This is inline JS"

这篇关于JQuery的html的()方法和外部脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆