开发者

Input field that gets cleared on document ready

开发者 https://www.devze.com 2023-01-24 02:46 出处:网络
What would be the bes开发者_运维知识库t way to clear an input field on $.(document).ready()? What I\'d like to happen is when the user reloads or navigates away and navigates back to the page, the in

What would be the bes开发者_运维知识库t way to clear an input field on $.(document).ready()?

What I'd like to happen is when the user reloads or navigates away and navigates back to the page, the input field clears when the DOM is ready.

I've tried innerHTML and value="" but those don't seem to work.


$.(document).ready(function{
$("input:text").val("");
});


When using a jQuery representation of a DOM element, use the val method:

$('input:text').val('');


Have you tried http://api.jquery.com/val/?


Setting the value should work, but don't use $(document).ready() or $(window).load() .
Depending on the browser those events may not fire if the user navigates using back/forward.

Just put it somewhere at the end of the document, beyond the last input-element.

0

精彩评论

暂无评论...
验证码 换一张
取 消