Javascript $(this).text()不包括空格后的文本

Javascript $(this).text()不包括空格后的文本,javascript,jquery,Javascript,Jquery,$('.ed_name')。替换为(函数(){ 返回“” }); Akshay Verma(Aks) 您在输入中忘记了双引号: $('.ed_name')。替换为(函数(){ 返回“” }); Akshay Verma(Aks)用于创建HTML元素,它将使您免受引号混乱和潜在问题的困扰 $('.ed_name')。替换为(函数(){ 返回$(''){ “占位符”:$(this).text(), “值”:$(this.html(), “类”:“ed_inp” }); //'' });

$('.ed_name')。替换为(函数(){
返回“”
});

    Akshay Verma(Aks)
您在输入中忘记了双引号:

$('.ed_name')。替换为(函数(){
返回“”
});

Akshay Verma(Aks)
用于创建HTML元素,它将使您免受引号混乱和潜在问题的困扰

$('.ed_name')。替换为(函数(){
返回$(''){
“占位符”:$(this).text(),
“值”:$(this.html(),
“类”:“ed_inp”
});
//''
});

    Akshay Verma(Aks)
您的属性值没有被引用,因此它们将以空格结尾。这里有半个修正:

$('.ed_name').replaceWith(function () {
    return '<input placeholder="'+$(this).text()+'" value="'+$(this).html()+'" class="ed_inp">'
});
$('.ed_name')。替换为(函数(){
返回“”
});
但正确的方法是创建元素,而不是HTML:

$('.ed_name').replaceWith(function () {
    return $('<input />', {
        placeholder: $(this).text(),
        value: $(this).html(),
        class: 'ed_inp',
    });
});
$('.ed_name')。替换为(函数(){
返回$(''){
占位符:$(this).text(),
值:$(this.html(),
类别:“ed_inp”,
});
});

您的代码完全按照它应该的方式工作
$('.ed_name')
指的是列表项(
  • )和其中的
    .text()
    ,即
    Akshay Verma(Aks)

    预期的结果是什么?我建议在JSFIDLE链接上使用堆栈片段