此代码在 IE 中给出错误
Internet Explorer 无法打开 Internet 站点操作中止,如何修复此错误?
var tip = "<p>Most computers will open PDF documents ";
tip += "automatically, but you may";
tip += "need to download <a title='Link to Adobe website-opens in a new window'";
tip +=" href='http://www.adobe.com/products/acrobat/readstep2.html'
target='_blank'>Adobe Reader</a>.</p>";
$(document).ready(function(){
//IF NUMBER OF PDF LINKS IS MORE THAN ZERO INSIDE DIV WITH ID maincontent
//THEN THIS WILL PUT TIP PARAGRAPH AS LAST CHILD OF DIV
if($("div#maincontent a[href*='/pdf']").length>0){
$("div#maincontent").children(":last-child").after(tip);
}
});
在 IE 中查看此页面:http://jsbin.com/oliho4 http://jsbin.com/oliho4
对我来说,很明显您尝试在页面完成加载之前修改某些元素。至少这正是您在演示页面上所做的。你没有将代码包装在$(document).ready()
正如你在问题中所做的那样
试试这个演示网站http://jsbin.com/ivuqa http://jsbin.com/ivuqa它正确地将相关行包装在ready()
此外,使用 XHTML 时可能会出现一些问题。在这种情况下,只需像这样包装有问题的 javascript 部分即可。 (CDATA 满足 XML 验证,javascript 多行注释隐藏 cdata,浏览器不理解它,因此无法运行 javascript。
/* <![CDATA[ */
var tip = "<p>Most computers will open PDF documents automatically, but you may need to download <a title='Link to Adobe website-opens in a new window'";
tip +=" href='http://www.adobe.com/products/acrobat/readstep2.html' target='_blank'>Adobe Reader</a>.</p>";
/* ]]> */
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)