方法:1、用attr(),語(yǔ)法“元素對(duì)象.attr("hidden",值)”;2、用prop(),語(yǔ)法“元素對(duì)象.prop("hidden",值)”;3、用removeAttr(),語(yǔ)法“元素.removeAttr("hidden")”。
本教程操作環(huán)境:windows7系統(tǒng)、jquery1.10.2版本、Dell G3電腦。
hidden 屬性規(guī)定對(duì)元素進(jìn)行隱藏。隱藏的元素不會(huì)被顯示。如果使用該屬性,則會(huì)隱藏元素。
jquery修改hidden屬性
1、使用attr()屬性設(shè)置hidden屬性的值
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <script src="js/jquery-1.10.2.min.js"></script> <script> $(document).ready(function() { $("button").click(function(){ $("div").attr("hidden",false); }); }); </script> </head> <body> <p>測(cè)試文字-p元素</p> <div hidden>測(cè)試文字-div元素</div> <p>測(cè)試文字-p元素</p> <button>修改hidden屬性 </button> </body> </html>
2、用prop()屬性設(shè)置hidden屬性的值
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <script src="js/jquery-1.10.2.min.js"></script> <script> $(document).ready(function() { $("button").click(function(){ $("div").prop("hidden",false); }); }); </script> </head> <body> <p>測(cè)試文字-p元素</p> <div hidden>測(cè)試文字-div元素</div> <p>測(cè)試文字-p元素</p> <button>修改hidden屬性 </button> </body> </html>
運(yùn)行效果和方法1一樣
3、用removeAttr()屬性刪除hidden屬性
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <script src="js/jquery-1.10.2.min.js"></script> <script> $(document).ready(function() { $("button").click(function(){ $("div").removeAttr("hidden"); }); }); </script> </head> <body> <p>測(cè)試文字-p元素</p> <div hidden>測(cè)試文字-div元素</div> <p>測(cè)試文字-p元素</p> <button>修改hidden屬性 </button> </body> </html>
運(yùn)行效果和方法1一樣
【推薦學(xué)習(xí):jQuery視頻教程、web前端視頻】