input click the button to restore the initial value

Use js to store the original value in a custom attribute before the page is initialized, and replace the current value with the initial value when the restore button is clicked

<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.4.1.min.js"></script>
<div id="dv"><!--The object to be restored is placed in a container, and only the operations under this container-->
    <input type="text" value="1"  /><input type="text" value="2"  /><input type="text" value="3"  />
</div>
<input type="button" value="还原" onclick="restore()" />
<script>
    $('#dv input').attr('initvalue', function () { return this.value})
    function restore() {
        $('#dv input').val(function () { return this.getAttribute('initvalue')})
    }
</script>

 

Reprinted from: https://ask.csdn.net/questions/197256

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326079362&siteId=291194637