开发者

How to clear the Text on Clear button using JQuery

开发者 https://www.devze.com 2022-12-17 09:35 出处:网络
I have a clear button that needs to clear the TextBox value(that is开发者_如何学Go entered) on this button click using JQuery function.You just need to attach a click event to the button that will set

I have a clear button that needs to clear the TextBox value(that is开发者_如何学Go entered) on this button click using JQuery function.


You just need to attach a click event to the button that will set the value of the input element to empty.

$("#clearButton").click(function() {
        $("#textbox1").val("");
});

Of course to give you exact selectors we need to see the actual html. The above jquery call would work for this html.

<button type="button" id="clearButton">Clear</button>
<input id="textbox1" type="text" value="" />


$('#' + fieldName).val("");

or you can use a class name like;

$('.' + fieldName).val("");

Class names are better sometimes when id's are changed in the environment.


Lets say you have a "thingtoclear" and a "thingtoclick" then you might want something like this:

    $(document).ready( function() {
       $('#thingtoclick').click( function () {
             $('#thingtoclear').val(""); 
       });
     });
0

精彩评论

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