jquery如何设置元素不可编辑?下面本篇文章给大家介绍一下使用jquery设置元素不可编辑的方法。有一定的参考价值,有需要的朋友可以参考一下,希望对大家有所帮助。
jquery如何设置元素不可编辑?
jquery 设置页面元素不可点击、不可编辑、只读(备忘)代码
$("input").attr('readonly', true); $("textarea").attr('readonly', true); $(':radio').attr('disabled', true); $(':checkbox').attr('disabled', true); $(':button').attr('disabled', true); $('a').removeAttr('onclic<span style="color:transparent">来源gaodai#ma#com搞*!代#%^码网</span>k'); $('select').attr('disabled', true);
在jquery中,可以通过使用attr()给元素(input、textarea、a、select等等)设置disabled属性,来禁用该元素,被禁用的元素,不可编辑,不可复制,不可选择。
例如:可以给input 元素添加disabled属性,来禁用 input 元素,被禁用的 input 元素,不可编辑。
<!DOCTYPE HTML> <html> <head> <meta charset="UTF-8"> <script src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script> </head> <body> <input type="text" value="不可编辑" /></br> </br> <script type="text/javascript"> $("input").on('click', function() { $(this).attr("disabled", true); //或者 //$(this).attr("disabled", "disabled"); }); </script> </body> </html>
说明:
disabled 属性禁用了input 元素,被禁用的 input 元素,不可编辑,不可复制,不可选择,不能接收焦点,后台也不会接收到传值。设置后文字的颜色会变成灰色。
注:disabled 属性无法与 <input type="hidden"> 一起使用。
更多web前端开发知识,请查阅 搞代码网 !!
以上就是jquery如何设置元素不可编辑?的详细内容,更多请关注gaodaima搞代码网其它相关文章!