是否可以在不实际编辑 postbody 变量内容的情况下替换'
postbody 变量中的'
var postbody = '<div class="postbody">this is tom's and bill's post</div>';
var postid = $('#post-content');
postid.append(postbody);
是否可以在不实际编辑 postbody 变量内容的情况下替换'
postbody 变量中的'
var postbody = '<div class="postbody">this is tom's and bill's post</div>';
var postid = $('#post-content');
postid.append(postbody);
创建一个元素并设置其文本,然后您不必对其进行编码:
var post = $('<div/>', { 'class': 'postbody' });
post.text("this is tom's and bill's post");
$('#post-content').append(post);
你可以使用
var postbody = '<div class="postbody">this is tom\'s and bill\'s post</div>';
或者
var postbody = "<div class=\"postbody\">this is tom's and bill's post</div>";
如果您真的想替换字符串中的某些内容,只需使用 replace():
var postbody = "<div class=\"postbody\">this is tom's and bill's post</div>";
postbody = postbody.replace(/\'/g, "'");
尝试使用这个
var postbody = "<div class='postbody'>this is tom's and bill's post</div>";
var postid = $('#post-content');
postid.append(postbody);