Sam*_*son 26
?$("div").on("click", function(){
$(this).text(function(index, text){
return text.replace(/^.(\s+)?/, '');
});
});????????????
Run Code Online (Sandbox Code Playgroud)
$("div").on("click", function(){
$(this).text(function(index, text){
return text.replace(/(\s+)?.$/, '');
});
});
Run Code Online (Sandbox Code Playgroud)
$("div").on("click", function(){
$(this).text(function(index, text){
return text.replace(/r/gi, '');
});
});
Run Code Online (Sandbox Code Playgroud)
在以下网址查看每个在线示例:http://jsfiddle.net/Xcn6s/
Tim*_*own 23
假设你有一个div的引用,它只包含一个文本节点(正如你的问题所暗示的),这很简单.这是一个非jQuery解决方案:
div.onclick = function() {
var textNode = this.firstChild;
textNode.data = textNode.data.slice(0, -1);
};
Run Code Online (Sandbox Code Playgroud)