如果我将类添加到<p> </p>,这个jquery代码不起作用的原因

时间:2010-04-24 12:32:44

标签: jquery xhtml

它有效

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

1 个答案:

答案 0 :(得分:3)

您在adobe-reader-download

所在的位置使用双引号
var tip = "<p class="adobe-reader-download">

试试这个:

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

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