开发者

Clear all textboxes client side

开发者 https://www.devze.com 2023-01-23 22:48 出处:网络
Can I Simulate this Co开发者_开发知识库de With JQUERY or Javascript? IEnumerable<TextBox> Textboxes = (from c in pnlform.Controlswhereobject.ReferenceEquals(c.GetType(), typeof(TextBox))c).AsEn

Can I Simulate this Co开发者_开发知识库de With JQUERY or Javascript?

    IEnumerable<TextBox> Textboxes = (from c in pnlform.Controlswhere    object.ReferenceEquals(c.GetType(), typeof(TextBox))c).AsEnumerable().Cast<TextBox>();
foreach (TextBox item in Textboxes) {
item.Text = string.Empty;
}

i want to clear all textboxes without any roundtrip to server.


Don't really understand that code, but to clear a textbox with jQuery:

$('someselector').val('');

So to clear all textboxes on a page:

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

Or you could use good old' form.reset()


Seems like you are trying to clear textboxes inside a panel pnlform. So in your selector you can give a context

$("input:text", "#yourpanelid").val('');


In a click function I have a link with class reset:

$('.reset').click(function(){
    $(':input','#formID')
     .val('')   
}); 


Use the reset button. It will reset all ( input | select | textarea ) elements within a form to their default values. The default values are specified by the element like so:

<input type="text" name="someName" value="this is a default value" />

with radio buttons and check boxes, it will return them to their default checked state.

Edit to add:
Reset buttons work well as a "cancel" button if you have a form where you are making changes to existing data.

0

精彩评论

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