开发者

How can i convert this statement to Jquery Completely

     if(document.getElementById('txt1') != null){
    $("#txt1").val(document.getElementById('txt1').value.toUpperCase());        
}

How can i convert this statement to Jquery开发者_如何学C Completely


You can use a function with .val() like this:

$("#txt1").val(function(i, val) { return val.toUpperCase(); });

...and it it doesn't find an id="txt1" element it just won't run on any, that's the way jQuery chains work, so your if() check is taken care of as well.


or like this

var $txt = $("#txt");
if($txt.length){
  $txt.val($txt.val().toUpperCase());
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜