为什么这个jQuery代码不工作,如果我添加类到<P>

有用

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>";


if($("div#maincontent a[href*='.pdf']").length>0){
    $("div#maincontent").children(":last-child").after(tip);

但不是

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);

您在这里使用双引号来表示adobe-reader-download

var tip = "<p class="adobe-reader-download">

尝试这个:

var tip = "<p class="adobe-reader-download">

注意:如果您为整个字符串使用单引号,则不需要转义双引号。

链接地址: http://www.djcxy.com/p/88841.html

上一篇: why this jquery code doesn't work if i add class to <P>

下一篇: Why doesn't SVG work on local HTML files?