问题描述
此代码在IE中出错
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中查看此页:
推荐答案
对我而言似乎很明显您尝试在页面加载完成之前修改某个元素。至少这正是你在演示页面上所做的。您没有像在问题中那样将代码包装在 $(document).ready()
中
To me it seems obvious that you try to modify some element before the page has finished loading. At least that's exactly what you do on your demo page. You don't wrap the code in $(document).ready()
as you did in the question
试试这个演示网站而不是正确包装<$中的相关行c $ c> ready()
Try this demo-site instead http://jsbin.com/ivuqa which correctly wraps the relevant lines in ready()
此外,使用XHTML时可能会出现一些问题。在这种情况下,只需包装违规的JavaScript部分。 (CDATA满足XML验证,javascript多行注释隐藏来自浏览器的cdata,不理解它,因此无法运行javascript。
Additionally there might be some problems when using XHTML. In that case just wrap the offending javascript part like this. (CDATA to satisfy the XML validation, javascript multiline comment to hide the the cdata from browser which don't understand it and thus would fail to run the 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>";
/* ]]> */
这篇关于Internet Explorer无法打开Internet站点操作已中止,如何解决此错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!