我确实有文本框和两个复选框,我可以在单击按钮时清除其值:
$("#cleartext").live('click', function () {
$(this).parents('form').find('input[type="text"]').val('');
$(".check").attr("checked", false);
});
但是我确实有一个文本区域,我正在使用HTML编辑器,但我无法清除它的价值,所以请建议我此元素的视图如下所示:
<input type="text" id="title" name="title" required title="required" placeholder="title" data-bind="value:title" />
<input type="checkbox" id="active" name="active" class="check" data-bind="checked: active=='true'" />Active
<input type="checkbox" id="logon" name="logon" class="check" data-bind="checked: use_logo=='true'" />Logo
<textarea id="iiii" name="iiii" class="htmleditor" rows="9" cols="50" style="width: 600px; height: 190px;"></textarea>
<button type="button" class="btn" id="cleartext">New Contract</button>
如果我
找到了正确的插件,下面应该可以正常工作:
$('#iiii').data("wysihtml5").editor.clear()
您正在使用哪个HTML编辑器。
FCK或类似的开源编辑器具有各自的方法来清除所有内容
例如
<script type="text/javascript">
function resetEditor(id) {
FCKeditorAPI.GetInstance(id).SetData('');
}
</script>.
对于 wysihtml5,请尝试以下操作
var rte = $('#description').wysihtml5();
rte.setValue('');
建议和更正
函数$.live()
已弃用。因此,请更改以下代码:
$("body").on('click', "#cleartext", function () {
$(this).parents('form').find('input[type="text"]').val('');
$(".check").attr("checked", false);
});
现在根据文本区域,例如。编校,您需要以这种方式清除:
editor.setCode('<p></p>');
正如Praveen Kumar所说,$.live()
已被弃用。以下内容应该有效,并清除文本区域:
$("body").on("click", "#cleartext", function() {
$(this).parents("#your-form").find("input[type='text']").val("");
$(".check").attr("checked", false);
$("#iiii").val("");
});
但是,如果您的函数被频繁调用,则应将$.on()
绑定到更近的块上。你也应该避免$.parents()
,因为这些函数很重。