Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/374.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在span文本后添加不在span标记内的文本_Javascript_Jquery_Html_Css - Fatal编程技术网

Javascript 在span文本后添加不在span标记内的文本

Javascript 在span文本后添加不在span标记内的文本,javascript,jquery,html,css,Javascript,Jquery,Html,Css,检查此屏幕截图: 我用这段代码在DIV中添加表情符号的跨度 $('body').on('click', '.selectable-icons', function(e) { if (e.target.tagName.toLowerCase() === 'span') { document.querySelector('[contenteditable]').appendChild(e.target.cloneNode(true)); $('[conten

检查此屏幕截图:

我用这段代码在DIV中添加表情符号的跨度

$('body').on('click', '.selectable-icons', function(e) {
    if (e.target.tagName.toLowerCase() === 'span') {
        document.querySelector('[contenteditable]').appendChild(e.target.cloneNode(true));
        $('[contenteditable]').append(" ");
        var current_text = $('[contenteditable]').html();
        alert(current_text);
        $('.publisher_div').html(current_text);
    }
但是
span
标记后面没有空格,因此我可以在
span
标记后面写下一个文本。

试试:

$('[contenteditable]').append(" ");
尝试:

$('[contenteditable]')。追加(“”)
将使用
contenteditable
属性(在您的示例中是
span
)向元素追加一个空格。如果要在之后添加空格,请使用:

实例:

var container=$(“#container”);
console.log(“之前:”);
container.contents().each(函数(索引){
console.log(索引,this.nodeType,this.nodeType==3?'“+this.nodeValue+'”:this.tagName);
});
$(“[contenteditable]”),在(“”)之后;
console.log(“之后:”);
container.contents().each(函数(索引){
console.log(索引,this.nodeType,this.nodeType==3?'“+this.nodeValue+'”:this.tagName);
});
这是跨度
$(“[contenteditable]”)追加(“”)
将使用
contenteditable
属性(在您的示例中是
span
)向元素追加一个空格。如果要在之后添加空格,请使用:

实例:

var container=$(“#container”);
console.log(“之前:”);
container.contents().each(函数(索引){
console.log(索引,this.nodeType,this.nodeType==3?'“+this.nodeValue+'”:this.tagName);
});
$(“[contenteditable]”),在(“”)之后;
console.log(“之后:”);
container.contents().each(函数(索引){
console.log(索引,this.nodeType,this.nodeType==3?'“+this.nodeValue+'”:this.tagName);
});
这是跨度
试试这个

  $('.publisher_div').append("hi");
试试这个

  $('.publisher_div').append("hi");

你能提供一把小提琴吗?你试过使用
?@hallleron:堆栈片段,而不是小提琴。你能提供一把小提琴吗?你试过使用
?@hallleron:堆栈片段,而不是小提琴。“在span文本之后添加文本…不在span标记内”
append
added in in。“在span text之后添加文本…不在span标记内”
append
adds in。