Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/88.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 将输入值转换或提取为纯文本_Javascript_Jquery_Html - Fatal编程技术网

Javascript 将输入值转换或提取为纯文本

Javascript 将输入值转换或提取为纯文本,javascript,jquery,html,Javascript,Jquery,Html,我有一个js函数,它将所有输入值转换为文本。 我只想将一行从转换为纯文本(所有行都有5个单元格和一个保存按钮),并使用该按钮将该行数据转换为纯文本。我试图使用。最近的对象,但我失败了 function disable_inp() { $("tr:gt(0) td:has(input)").text(function() { return $('input', this).val(); }); } 您应该使用:eq,而不是:gt。eq获取选择的索引,而gt大于

我有一个js函数,它将所有输入值转换为文本。 我只想将一行从转换为纯文本(所有行都有5个单元格和一个保存按钮),并使用该按钮将该行数据转换为纯文本。我试图使用。最近的对象,但我失败了

 function disable_inp() {
    $("tr:gt(0) td:has(input)").text(function() {
      return $('input', this).val();
    });
  }

您应该使用
:eq
,而不是
:gt
eq
获取选择的索引,而
gt
大于

function disable_inp() {
  $("tr:eq(0) td:has(input)").text(function() {
    return $('input', this).val();
  });
}
通过该按钮,您可以执行相同的操作:

$("button").click(function disable_inp() {
  $(this).closest("tr").find("td:has(input)").text(function() {
    return $('input', this).val();
  });
});
在这里,
.closest()
将找到与所选内容匹配的第一个父项并从此处应用。

按钮。单击(函数(){
button.click(function(){
    var $row = $(this).parent().parent(); //assuming it's not wrapped this will be the <tr>
    $row.find("td").each(function(){
        var plaintext = $(this).text();
        // do stuff with the plaintext
    });
});
var$row=$(this.parent().parent();//假设它没有包装,这将是 $row.find(“td”).each(函数(){ var plaintext=$(this.text(); //用纯文本做东西 }); });
Array-to-string转换…您是否也熟悉发布HTML的方法。还有,你只想在第一行上做,而不想在其他行上做?是的,我知道,我想在按钮所在的行上做。我正在使用数组创建行。我可以把html放在后面,我现在在手机上写,js函数是我唯一记得的东西。最好在外面写解释。