jQuery判断一个元素是显示还是隐藏,jQuery使用is()方法来判断一个元素是否显示,反之则为隐藏
核心代码
if($("#username").is(":hidden")){ }
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>test.html</title> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="this is my page"> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <script type="text/javascript" src="../../WEB-FACE/script/jquery-1.8.0.min.js"></script> <script type="text/javascript"> $(function(){ if($("#userid").is(":hidden")){ alert("隐藏"); }else{ alert("可见"); } }) </script> </head> <body> <input type="text" id="username" value="admin" /> <input type="password" id="password" value="123456"/> <input type="hidden" id="userid" value="1001003004016"> <input type="text" id="address" disabled="disabled" value="北京市海淀区"/> </body> </html>
同样判断元素是否可编辑 如下
if($("#address").is(":disabled")){ alert("不可编辑"); }else{ alert("可编辑"); }
转载请注明出处:http://blog.csdn.net/itmyhome1990?viewmode=contents
原文地址:http://blog.csdn.net/itmyhome1990/article/details/39008077