JS控制页面输入框为只读

编程技术  /  houtizong 发布于 2年前   95

在WEB应用开发当中,增、删除、改、查功能必不可少,为了减少以后维护的工作量,我们一般都只做一份页面,通过传入的参数控制其是新增、修改或者查看。而修改时需将待修改的信息从后台取到并显示出来,实际上就是查看的过程,唯一的区别是修改时,页面上所有的信息能修改,而查看页面上的信息不能修改。因此完全可以将其合并,但通过前端JS将查看页面的所有信息控制为只读,在信息量非常大时,就比较麻烦。

    其实前端的所有JS输入框都是input,所以可通过$("#table1 :input").attr("disabled",true);达到目的,此功能的验证实例如下:

<html xmlns="http://www.w3.org/1999/xhtml"><head>    <title></title>    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" type="text/javascript"></script>     <script type="text/javascript">        function setDisabled(bo) {            $("#table1 :input").attr("disabled",bo);        }    </script></head><body>    <input id="Button1" type="button" value="启用" onclick="setDisabled(false)" />    <input id="Button2" type="button" value="禁用" onclick="setDisabled(true)" />    <table id="table1" >        <tr>            <td>                <input id="Text1" type="text" />            </td>            <td>                <input id="Password1" type="password" />            </td>        </tr>        <tr>            <td>                <select id="Select1">                    <option>1</option>                </select>            </td>            <td>                <input id="Checkbox1" type="checkbox" />                <input id="Radio1" type="radio" />            </td>        </tr>        <tr>            <td>                <input id="File1" type="file" />            </td>            <td>                <textarea id="TextArea1" cols="20" rows="2"></textarea>            </td>        </tr>    </table></body></html>

 

 

请勿发布不友善或者负能量的内容。与人为善,比聪明更重要!

留言需要登陆哦

技术博客集 - 网站简介:
前后端技术:
后端基于Hyperf2.1框架开发,前端使用Bootstrap可视化布局系统生成

网站主要作用:
1.编程技术分享及讨论交流,内置聊天系统;
2.测试交流框架问题,比如:Hyperf、Laravel、TP、beego;
3.本站数据是基于大数据采集等爬虫技术为基础助力分享知识,如有侵权请发邮件到站长邮箱,站长会尽快处理;
4.站长邮箱:[email protected];

      订阅博客周刊 去订阅

文章归档

文章标签

友情链接

Auther ·HouTiZong
侯体宗的博客
© 2020 zongscan.com
版权所有ICP证 : 粤ICP备20027696号
PHP交流群 也可以扫右边的二维码
侯体宗的博客