[英]Why this code works with jquery 1.3.2 but not with 1.4.2?
此代碼
var tip = "<p class='adobe-reader-download'>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>";
if($("div#maincontent a[href*='.pdf']").length>0){
$("div#maincontent").children(":last-child").after(tip);
與此作品很好
<script
src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"
type="text/javascript"></script>
但不能與此一起工作
<script
type="text/jscript"
src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js">
</script>
“不起作用”是什么意思? 提示沒有附加到頁面上嗎? 提示鏈接無效嗎? 當您說“不起作用”時,請多描述一下,告訴我們如何做。
我在此處制作了此代碼的示例: http : //jsbin.com/akugo/edit
使用JSBin,您可以告訴它要使用的jQuery版本,而我已經使用1.3.2和1.4.2對其進行了測試,但沒有發現任何問題。 我從發布的代碼中更改的唯一一件事是,我用方括號(“}”)結束了“ if”語句。
$(document).ready(function() {
var tip = "<p class='adobe-reader-download'>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>";
if ($("div#maincontent a[href*='.pdf']").length > 0) {
$("div#maincontent").children(":last-child").after(tip);
}
});
有了這個:
<div id="maincontent">
<a href="sample.pdf">your pdf</a>
</div>
對於jq 1.4的輸出:
您的pdf
大多數計算機會自動打開PDF文檔,但是您可能需要下載Adobe Reader。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.