用各自的特殊字符自动替换特殊字符代码
问题描述:
$('#emailsubmit').click(function(){
var data = CKEDITOR.instances.message.getData();
data=data.replace(/\"/g,'"');
data=data.replace(/ /g,' ');
data=data.replace(/©/g,'©');
$('#message_text').val(data);
});
这是用特殊字符替换特殊字符代码的jquery函数。我手动设置它,我想自动设置,这可以怎么做?用各自的特殊字符自动替换特殊字符代码
答
function replace_word(){
var data = CKEDITOR.instances.message.getData();
data=data.replace(/\"/g,'"');
data=data.replace(/ /g,' ');
data=data.replace(/©/g,'©');
$('#message_text').val(data);
}
并在您使用的任何输入的按键上使用此功能。
答
你想做什么看起来很像html解码。与任何 HTML实体支持 - - 完成同样的事情的一个更好的方法是显示here的方法:
// Get the encoded string from the editor
var data = CKEDITOR.instances.message.getData();
// Decode it - this is where the magic happens =)
var decoded = $("<div/>").html(data).text();
// Set the textbox value
$('#message_text').val(decoded);
由于Vaibs_Cool在他的回答表明,你可以在一个函数把这个包,然后设置它可以作为你想触发的任何事件的事件处理函数。
是否有任何功能用特殊字符替代特殊字符代码,如“可以用"等代替”。 – Babby 2014-11-21 07:34:14