Checking if a button exists
I have a .js file that is invoked by a few .jsp pages. What I need to do in this particular .js file is to invoke a certain function only if the 'save' button is present in the .jsp page. How do I check if the the button exists? Currently in the .js file the button is refered to this way: $('button[id=save]')
How do I check if such a button exists? Hope someone can advise. Thanks.
尝试这样的事情
$(document).ready(function(){
//javascript
if(document.getElementById('save')){
//your code goes here
}
//jquery
if($('#save').length){
//your code goes here
}
});
你可以这样做:
if($('#save').length > 0){
// Button exists
} else {
// Button is not present in the DOM yet
}
链接地址: http://www.djcxy.com/p/83698.html
上一篇: 通过jQuery检查块的存在
下一篇: 检查是否存在按钮