Sug*_*gsy 2 javascript jquery textarea
我有这个代码,可以很好地重置表单
<script type="text/javascript">
$("#formname").resetForm();
</script>
Run Code Online (Sandbox Code Playgroud)
但我想清除文本区域.这可能吗?
清除和重置是两回事.清除意味着将值设置为空字符串,而重置意味着将值设置为它的初始值.
明确:
$('#textAreaId').val('');// clears the textarea.
Run Code Online (Sandbox Code Playgroud)
重置为textarea初始值而不是重置它:
var t = document.getElementById('textAreaId');
t.value = t.defaultValue;
Run Code Online (Sandbox Code Playgroud)
defaultValue 最初在创建此对象的HTML中指定的默认值.