admin管理员组

文章数量:1393409

As you might guess I'm building a small chat system, and I would like that when the user clicks enter the message would be sent and the text area cleared.

I'm using this jquery:

 jQuery('#my-form')[0].reset();

and it reloads the page which looks really noob.

any ideas?

As you might guess I'm building a small chat system, and I would like that when the user clicks enter the message would be sent and the text area cleared.

I'm using this jquery:

 jQuery('#my-form')[0].reset();

and it reloads the page which looks really noob.

any ideas?

Share Improve this question asked Nov 30, 2011 at 22:43 coisocoiso 7,47912 gold badges47 silver badges63 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 4
$('#textbox1').val('');

Should clear a textbox

Assuming that your text-input/textarea is properly within a form, why not use:

<input type="reset" value="Clear the box" />

JS Fiddle demo.

Or:

<button type="reset">clear the text</button>

JS Fiddle demo.

本文标签: javascriptreset form element without reloading pageStack Overflow