我正在写一个wordpress插件注入一些JavaScript和HTML到一个职位。使用“the_content”过滤器我设法插入我的标签与我所有的JavaScript函数和所有我的HTML标记之后。问题是脚本不工作,萤火虫标签它是一个语法错误,而不是非常精确的错误在哪里。使用WordPress的the_content过滤器注入JavaScript产生JavaScript语法错误
下面是插入页面的javascript标记的内容,当我检查它时,它似乎没有任何类型的语法错误。
<![CDATA[
Votes = {};
$(document).ready(function()
{
$(".starContainer span").hover(sr_addBG("http://revealcoupons.com/wp-content/plugins/StarRatingLite/images/stars.png"), sr_removeBG());
});
function sr_addBG(ImgURL){
$(this).css("background","transparent url("+ImgURL+") repeat-x 0 -60px");
}
function sr_removeBG(){
$(this).css("background","none");
}
function sr_castVote(ID,Vote, ImgURL){
Votes[ID] = Vote;
$("#starContainer"+ID+" span").css("background","none");
$("ID"+ID+"Star"+Vote).css("background","transparent url("+ImgURL+") repeat-x 0 -60px");
}
function sr_verifyVote(NbFeatures){
var count = 0;
for (var e in Votes)
{count++;}
return count >= NbFeatures;
}
function sr_submitVotes(NbFeatures, PostID){
if (sr_verifyVote(NbFeatures))
{
ajaxReq = new XMLHttpRequest();ajaxReq.onreadystatechange=function()
{
if (ajaxReq.readyState == 4 && ajaxReq.status == 200)
{
alert("BAM! vote submitted. Thank you");
}
}
var voteStr = "";
for (var vote in Votes)
{voteStr += vote+"[eq]"+Votes[vote]+"[amp]";}
voteStr = voteStr.substring(0, voteStr.length - 5);
ajaxReq.open("http://revealcoupons.com/wp-content/plugins/StarRatingLite/StarRatingLite.php?PostID="+PostID+"&votes="+voteStr");
ajaxReq.send();
}
else
{
alert("You must vote on all features before submitting your opinion.");
}
}]]>
萤火虫产生的唯一错误是“语法错误”,而不是更具体。我唯一没有写的东西就是cdata部分的结尾,其中“>”字符被“>”自动替换。
感谢您的任何意见!
可以粘贴Firebug的错误输出? – Einacio
萤火虫输出实际上是整个JavaScript没有换行符和标签,因为我用preg_replace删除它们。我重新格式化了它的可读性 – Louis