Javascript jquery-在预结束内容时转义引号问题

Javascript jquery-在预结束内容时转义引号问题,javascript,jquery,escaping,Javascript,Jquery,Escaping,我尝试使用以下代码段: $('#thirdPartyCheckoutButtons').prepend('<a href="https://www.resellerratings.com" onclick="window.open("https://seals.resellerratings.com/landing.php?seller=myID","name","height=760,width=780,scrollbars=1"); return false;"><img

我尝试使用以下代码段:

$('#thirdPartyCheckoutButtons').prepend('<a href="https://www.resellerratings.com" onclick="window.open("https://seals.resellerratings.com/landing.php?seller=myID","name","height=760,width=780,scrollbars=1"); return false;"><img style="border:none;" src="//seals.resellerratings.com/seal.php?seller=myID" oncontextmenu="alert("Copying Prohibited by Law - ResellerRatings seal is a Trademark of All Enthusiast, Inc."); return false;" /></a><img src="https://www.myurl.com/hdsd834k.png"  style="float: left;margin-left: 180px;">');
$(“#第三方检查按钮”)。前置(“”);

它根本没有显示出来。。我试过这么多的报价差异,我不明白

内部双引号正在破坏onclick属性值。将它们替换为单引号并转义

...onclick="window.open(\'https://seals.resellerratings.com/landing.php?seller=myID\',\'name\',\'height=760,width=780,scrollbars=1\'); return false;"...
在oncontextmenu事件中也会发生同样的情况,请执行相同的修复

...oncontextmenu="alert(\'Copying Prohibited by Law - ResellerRatings seal is a Trademark of All Enthusiast, Inc.\'); return false;" />...
完整代码:

$('#thirdPartyCheckoutButtons').prepend('<a href="https://www.resellerratings.com" onclick="window.open(\'https://seals.resellerratings.com/landing.php?seller=myID\',\'name\',\'height=760,width=780,scrollbars=1\'); return false;"><img style="border:none;" src="//seals.resellerratings.com/seal.php?seller=myID" oncontextmenu="alert(\'Copying Prohibited by Law - ResellerRatings seal is a Trademark of All Enthusiast, Inc.\'); return false;" /></a><img src="https://www.myurl.com/hdsd834k.png"  style="float: left;margin-left: 180px;">');​
$(“#第三方检查按钮”)。前置(“”);​

内部双引号正在破坏onclick属性值。将它们替换为单引号并转义

...onclick="window.open(\'https://seals.resellerratings.com/landing.php?seller=myID\',\'name\',\'height=760,width=780,scrollbars=1\'); return false;"...
在oncontextmenu事件中也会发生同样的情况,请执行相同的修复

...oncontextmenu="alert(\'Copying Prohibited by Law - ResellerRatings seal is a Trademark of All Enthusiast, Inc.\'); return false;" />...
完整代码:

$('#thirdPartyCheckoutButtons').prepend('<a href="https://www.resellerratings.com" onclick="window.open(\'https://seals.resellerratings.com/landing.php?seller=myID\',\'name\',\'height=760,width=780,scrollbars=1\'); return false;"><img style="border:none;" src="//seals.resellerratings.com/seal.php?seller=myID" oncontextmenu="alert(\'Copying Prohibited by Law - ResellerRatings seal is a Trademark of All Enthusiast, Inc.\'); return false;" /></a><img src="https://www.myurl.com/hdsd834k.png"  style="float: left;margin-left: 180px;">');​
$(“#第三方检查按钮”)。前置(“”);​
prepend()函数中的字符串由单引号分隔。这意味着您在该字符串中键入的每个引号都必须由。然而,这不是你的问题。您的问题在于无效的HTML。这就是你所拥有的:

$('#thirdPartyCheckoutButtons').prepend('<a href="https://www.resellerratings.com" onclick="window.open("https://seals.resellerratings.com/landing.php?seller=myID","name","height=760,width=780,scrollbars=1"); return false;"><img style="border:none;" src="//seals.resellerratings.com/seal.php?seller=myID" oncontextmenu="alert("Copying Prohibited by Law - ResellerRatings seal is a Trademark of All Enthusiast, Inc."); return false;" /></a><img src="https://www.myurl.com/hdsd834k.png"  style="float: left;margin-left: 180px;">');
$(“#第三方检查按钮”)。前置(“”);
如果注意到所有HTML属性值都用双引号分隔。但是,在onclick=”“事件中,您再次使用双引号。您可以使用转义单引号来修复此冲突。您的oncontextmenu=“”事件中也存在同样的问题

$(“#第三方检查按钮”)。前置(“”);
将来避免此问题的最简单方法是在jQuery函数调用之外构建字符串(HTML),然后将字符串作为变量传入。

prepend()函数中的字符串用单引号分隔。这意味着您在该字符串中键入的每个引号都必须由。然而,这不是你的问题。您的问题在于无效的HTML。这就是你所拥有的:

$('#thirdPartyCheckoutButtons').prepend('<a href="https://www.resellerratings.com" onclick="window.open("https://seals.resellerratings.com/landing.php?seller=myID","name","height=760,width=780,scrollbars=1"); return false;"><img style="border:none;" src="//seals.resellerratings.com/seal.php?seller=myID" oncontextmenu="alert("Copying Prohibited by Law - ResellerRatings seal is a Trademark of All Enthusiast, Inc."); return false;" /></a><img src="https://www.myurl.com/hdsd834k.png"  style="float: left;margin-left: 180px;">');
$(“#第三方检查按钮”)。前置(“”);
如果注意到所有HTML属性值都用双引号分隔。但是,在onclick=”“事件中,您再次使用双引号。您可以使用转义单引号来修复此冲突。您的oncontextmenu=“”事件中也存在同样的问题

$(“#第三方检查按钮”)。前置(“”);

今后避免此问题的最简单方法是在jQuery函数调用之外构建字符串(HTML),然后将字符串作为变量传入。

这是一个HTML属性值;\没有意义。它是一个HTML属性值;\这是毫无意义的。