简体   繁体   English

如何使用javascript从输入中清除数据属性

[英]how to clear data attribute from input using javascript

How do I clear the userid attribute of a specific input field? 如何清除特定输入字段的userid属性? Even when I clear the field the userid is not cleared, because I am fetching the data on the basis of the ID in input field of the textbox, it also fetches the data of the userid which is not present in the textbox because it gets stored and is removed only after refresh(f5). 即使当我清除该字段时,也不会清除userid ,因为我是根据文本框输入字段中的ID来获取数据的,所以它也会获取文本框中不存在的userid数据,因为它已经存储了并且仅在refresh(f5)之后删除。

<input id="inputField_0" 
       type="text" 
       class="inputClass ui-autocomplete-input" 
       autocomplete="off" 
       userid="10018" />

You can leverage jQuery's removeAttr method. 您可以利用jQuery的removeAttr方法。

$("#inputField_0").removeAttr("userid");

Or if you need a vanilla JS option, you can leverage the element's removeAttribute method. 或者,如果您需要普通的JS选项,则可以利用元素的removeAttribute方法。

document.getElementById("inputField_0").removeAttribute("userid"); 

You can remove userid attribute from input field using JQuery. 您可以使用JQuery从输入字段中删除userid属性。

Try the below link.
Visit [https://jsfiddle.net/gmk9zotq/3/]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM