【发布时间】:2014-09-22 19:14:44
【问题描述】:
我有一个社交网站,一切正常,我唯一的问题是每当我在评论或评论字段中输入双问号时,它会显示奇怪的文字。
===========
如果我输入“你好??” 它打印出来像这样“hellojQuery110205576835575724747_1411410901236”, 我想知道如何转义特殊字符,在我的情况下是双问号。 没有正则表达式有没有更好的方法来做到这一点。 提前致谢。 这是我的代码。
$(document).undelegate('.comment', 'keypress').delegate('.comment', 'keypress', function(e) {
if ($.trim($(this).val()) !== '') {
if (e.which === 10 || e.which === 13) {
var comment = $(this).val();
var id = $(this).closest('.review_list').attr('id');
$.ajax({
type: 'POST',
url: '../controller/pageController.php',
data: 'review_id=' + id + '&comment=' + comment + '&luser_id=' + luser_id,
dataType:'json',
cache: false,
success: function(id) {
if($.trim(id)=='NO'){
window.location='profile.php';
}
id = $.trim(id.id);
var c = "<li id='" + id + "'><div id='c_thumb'>"+(thumb != null ? '<img src="profile_images/' + thumb + '"/>' : '')+"</div><div id='commenter'><a href='userprofile.php?id="+luser_id+"'>" + name + "</a></div><div id='time'> 0 second ago</div><p>" + comment + "</p><a id='c_remove' href=''>remove</a></li>";
$('#comment_box li:last-child').before(c);
document.getElementById("post_comment").reset();
}//end of success
});
}
}
});
【问题讨论】:
标签: javascript jquery regex escaping