jquery怎么移除readonly

使用jquery移除readonly属性的方法:1.新建html项目,引入jquery;2.创建input输入框,设置id和readonly只读属性;3.添加button按钮,绑定onClick点击事件;4.通过id获取input对象,使用removeAttr()方法移除readonly属性;

具体步骤如下:

1.首先,新建一个html项目,并在项目中引入jquery;


<script type="text/javascript" src="/static/jquery-2.1.4.min.js"></script>

2.引入jquery后,在项目中创建一个input输入框,并设置id和readonly只读属性;

<input type="text" value="" id="btn" readonly />


3.input输入框创建好后,添加一个button按钮,并绑定onclick点击事件,用于点击移除;


<button onClick="set()"><button>

4.最后,按钮添加好后,在点击事件中通过id获取input对象,在使用removeAttr()方法即可移除readonly属性;

function set(){

$("#btn").removeAttr('readonly');

}


Both comments and pings are currently closed.

Comments are closed.

Powered by KingAbc | 粤ICP备16106647号-2 | Loading Time‌ 0.212