【发布时间】:2011-12-21 06:20:50
【问题描述】:
我正在编写一个 wordpress 插件来将一些 javascript 和 html 注入到帖子中。使用“the_content”过滤器,我设法在我的所有 javascript 函数和我的所有 html 标记之后插入我的标签。问题是脚本不起作用,firebug 将其标记为语法错误,而没有非常精确地确定错误所在。
这是插入到页面中的 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 输出实际上是整个 javascript,没有换行符和制表符,因为我使用 preg_replace 删除了它们。为了便于阅读,我重新格式化了它
标签: javascript wordpress filter