如何使用localstorage清除textarea字段

时间:2012-12-29 17:23:45

标签: html5 local-storage

我想使用以下方法清除我的textarea字段。 这是我的代码:

<form  id="localStorageTest" action="" method="post">
<textarea cols="100000" rows="100000" style="height: 150px; width: 200px;" readonly="readonly" name="hhhh" id="txt1"></textarea>
<textarea cols="1000" rows="100000" style="height: 20px; width: 190px;" name="txtarea" id="txt3" class="stored"></textarea>
<input type="button" name="button" onclick="insertdata(txtarea.value)" value="send"/>
    </form>

我想清除id为txt3的字段。我这样做了以下......

    $('#txt3').button(function() {
    localStorage.clear();
})

但它不起作用。我的代码在哪里或什么是问题。 请有人帮帮我。 提前谢谢。

1 个答案:

答案 0 :(得分:1)

您的代码会导致错误。我不知道你要做什么?单击按钮应清除textarea。为什么onclick属性呢?

您应该为按钮指定一个ID。选择它更容易

我假设你正在使用jquery,所以:

<强> HTML:

<input id="myButton" type="button" name="button" ...>

<强> JS:

$('#myButton').on('click', function() {
    $('#txt3').value = '';
});