如何在没有删除输入的情况下清空td的值?

时间:2016-06-14 10:53:45

标签: javascript jquery html

我想要删除自定义td的值。

<td> <input type="hidden" name="myinput" value="1"> some text </td>

我不想删除输入,只想删除一些文本。有什么帮助?

2 个答案:

答案 0 :(得分:1)

然后只调用textContent方法

来更新text

例如,

//$("td").text(""); //Doesn't work

//$("td")[0].textContent = ""; //Doesn't work

//convert childNodes to Array and then iterate through the same
Array.prototype.slice.call( $("td")[0].childNodes ).forEach(function(node){
  node.nodeType == 3 && node.parentNode.removeChild(node); //if the node is a text node then remove the same
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table>
  <tr>
    <td>
      <input type="hidden" name="myinput" value="1">some text</td>
  </tr>
</table>

答案 1 :(得分:0)

香草溶液

&#13;
&#13;
<table>
<td> <input type="text" name="myinput" value="1"> some text </td>
</table>
&#13;
{
    ... // your JSON properties here
    "serviceProperties": { // properties for service
        "ServiceEndpoint": "https://somedomain:1200/web/Servlet/SOAP/Services",
        "Certificates": false,
        "DocumentName": "note.pdf"
    }
}
&#13;
&#13;
&#13;