开发者

Reset Particular Input Element in a HTML Form

开发者 https://www.devze.com 2022-12-27 14:39 出处:网络
I have multiple input textboxes in my page. I want to reset particular text box to its onload state if certain conditions fails.

I have multiple input textboxes in my page. I want to reset particular text box to its onload state if certain conditions fails. I am considering using a Hidden element to store the onload state of 开发者_如何转开发the textbox. I would other suggestions or solutions to resolve this issue.


defaultValue:

<input type="text" value="initial" id="field">
<button id="reset">reset</button>
<script type="text/javascript">
    document.getElementById('reset').onclick= function() {
        var field= document.getElementById('field');
        field.value= field.defaultValue;
    };
</script>

Available on text, password and textarea, plus defaultChecked on checkbox/radio and defaultSelected on option. Curiously, not available on hidden (except in IE, where it's considered a bug).

0

精彩评论

暂无评论...
验证码 换一张
取 消