开发者

How to clear the Text on Clear button using JQuery

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜