jquery對標(biāo)簽添加只讀(readonly)或者禁用(disabled)屬性
一、jQuery
jQuery
是一個JavaScript
庫。- jQuery 極大地簡化了 JavaScript 編程。
- jQuery 很容易學(xué)習(xí)。
實(shí)例:
$(document).ready(function(){ ? $("p").click(function(){ ? ? $(this).hide(); ? }); });
源碼:
<!DOCTYPE html> <html> <head> <meta charset="utf-8">? <title></title>? <script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js"> </script> <script> $(document).ready(function(){ ? $("p").click(function(){ ? ? $(this).hide(); ? }); }); </script> </head> <body> <p>如果你點(diǎn)我,我就會消失。</p> <p>繼續(xù)點(diǎn)我!</p> <p>接著點(diǎn)我!</p> </body> </html>
運(yùn)行結(jié)果:
上圖運(yùn)行結(jié)果只要點(diǎn)擊文字就會消失,感興趣的小伙伴可以下去試一下
二、關(guān)于readonly屬性
例1、jquery 設(shè)置readonly屬性
$('input').attr("readonly","readonly") //將input元素設(shè)置為readonly $('input').removeAttr("readonly"); //去除input元素的readonly屬性 ?? if($('input').attr("readonly") == true)//判斷input元素是否已經(jīng)設(shè)置了readonly屬性
例2、對于為元素設(shè)置readonly屬性和取消readonly屬性的方法
$('input').attr("readonly",true)//將input元素設(shè)置為readonly $('input').attr("readonly",false)//去除input元素的readonly屬性 ? $('input').attr("readonly","readonly")//將input元素設(shè)置為readonly $('input').attr("readonly","")//去除input元素的readonly屬性
三、jquery 設(shè)置disabled屬性
例1、jquery 設(shè)置disabled屬性
$('input').attr("disabled","disabled")//將input元素設(shè)置為disabled $('input').removeAttr("disabled");//去除input元素的disabled屬性 ?? if($('input').attr("disabled")==true)//判斷input元素是否已經(jīng)設(shè)置了disabled屬性
例2、對于為元素設(shè)置disabled屬性和取消disabled屬性的方法
$('input').attr("disabled",true)//將input元素設(shè)置為disabled $('input').attr("disabled",false)//去除input元素的disabled屬性 ? $('input').attr("disabled","disabled")//將input元素設(shè)置為disabled $('input').attr("disabled","")//去除input元素的disabled屬性
四、jquery動態(tài)添加文本框的readonly只讀屬性
<input id="test" type="text" ?/> ? ?$("#test").attr({"readonly":"readonly"}); //添加readonly屬性 ?// 或者 ?$("#ID").attr({ readonly: 'true' }); ?$("#test").removeAttr("readonly"); ? ?//去除readonly屬性
到此這篇關(guān)于jquery對標(biāo)簽添加只讀(readonly)或者禁用(disabled)屬性的文章就介紹到這了,更多相關(guān)jquery對標(biāo)簽添加只讀或禁用屬性內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
基于MVC5和Bootstrap的jQuery TreeView樹形控件(一)之?dāng)?shù)據(jù)支持json字符串、list集合
這篇文章主要介紹了基于MVC5和Bootstrap的jQuery TreeView樹形控件(一)之?dāng)?shù)據(jù)支持json字符串、list集合的相關(guān)者,小編推薦使用返回list集合的方法,具體原因大家可以根據(jù)本文學(xué)習(xí)下2016-08-08jQuery實(shí)現(xiàn)的點(diǎn)擊圖片居中放大縮小功能示例
這篇文章主要介紹了jQuery實(shí)現(xiàn)的點(diǎn)擊圖片居中放大縮小功能,涉及jQuery基于事件響應(yīng)針對頁面元素動態(tài)操作相關(guān)實(shí)現(xiàn)技巧,需要的朋友可以參考下2019-01-01jquery實(shí)現(xiàn)不同大小瀏覽器使用不同的css樣式表的方法
這篇文章主要介紹了jquery實(shí)現(xiàn)不同大小瀏覽器使用不同的css樣式表的方法,需要的朋友可以參考下2014-04-04jQuery EasyUI 中文API Button使用實(shí)例
jQuery EasyUI 中文API Button使用小結(jié),需要的朋友可以參考下。2010-04-04Jquery使用JQgrid組件處理json數(shù)據(jù)
這篇文章介紹了Jquery使用JQgrid組件處理json數(shù)據(jù)的方法,文中通過示例代碼介紹的非常詳細(xì)。對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2022-06-06jQuery實(shí)現(xiàn)電梯導(dǎo)航模塊
這篇文章主要為大家詳細(xì)介紹了jQuery實(shí)現(xiàn)電梯導(dǎo)航模塊,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下2020-12-12jQuery 循環(huán)遍歷改變a標(biāo)簽的href(實(shí)例講解)
下面小編就為大家?guī)硪黄猨Query 循環(huán)遍歷改變a標(biāo)簽的href(實(shí)例講解)。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-07-07jquery簡單實(shí)現(xiàn)帶漸顯效果的選項(xiàng)卡菜單代碼
這篇文章主要介紹了jquery簡單實(shí)現(xiàn)帶漸顯效果的選項(xiàng)卡菜單代碼,可實(shí)現(xiàn)tab選項(xiàng)卡切換過程中帶有漸顯效果,具有一定參考借鑒價值,需要的朋友可以參考下2015-09-09