当项目展开时,我使用
jQuery附加了一些
JavaScript.
但jQuery函数里面的JavaScript代码导致其余的jQuery代码爆炸.
$(this).parent('li').find('.moreInfo').append('<script>alert("hello");</script>');
我该怎么办来解决这个问题?
解决方法
对于附加的JavaScript问题,请使用:
var str="<script>alert('hello');";
str+="<";
str+="/script>";
$(this).parent('li').find('.moreInfo').append(str);
否则一个更好的选择将是线上li的点击事件:
$("ul#myList li").click(function(){
$.ajax({
type: "POST",contentType: "application/json; charset=utf-8",url: "url to your content page",data: "{}",//any data that you want to send to your page/service
dataType: "json",success: function(msg) {
$(this).find('.moreInfo').append(msg);
}
});
});
其实我不知道你使用什么语言.如果您使用ASP.NET,请阅读Dave的blog.