简体   繁体   中英

Reset form on back button (safari)

I'm trying to reset the form when the user click on the back button. Here is the code that I use.

<input type="text" name="name">
<input type="text" name="email>
...
$(function() {
   $('input[type=text]').attr('val', '');
});

This code is not working on Safari 6.0.2. I notice that the page load event is not even fired when the user click on the back button.

What could be the problem ?

There's no val attribute. Use the val method instead:

$(function() {
   $('input[type=text]').val('');
});

And, you missed a quote at the email field:

<input type="text" name="email>
                              ^ Insert a quote here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM