限时优惠活动
亲爱的苦力吧用户,我们为了回馈新老用户一直以来的鼎力支持,即日起(2025-02-06至2025-03-06)凡是购买苦力吧VIP/充值K币的新老用户,都直接可获得买一送一的优惠馈赠。例如:购买一个月的VIP会员可直接获得两个月的VIP会员;充值100K币可直接获得200K币,以此类推!有任何疑问可联系在线客服,感谢各位用户对苦力吧素材的信任与厚爱,我们将一如既往的给大家上新更多优质的素材源码,祝大家开工大吉、工作顺利、心想事成。

jquery表单元素自定义只读插件

所属分类: 网页特效-表单验证    2023-08-18 07:48:53

jquery表单元素自定义只读插件 ie兼容6
 查看演示  登录后下载 温馨提示
登录会员即可享受免费下载
 我要建站

jquery表单元素自定义只读插件(共2个文件)

    • serenix_readonly.js
    • index.html

使用方法

            var input = document.getElementById('readonly-text-input');
            console.log("\n'readonly-text-input' has attribute readonly : " + input.hasAttribute("readonly"));
            console.log("input element with ID 'readonly-text-input' attribute readonly value : " + input.getAttribute("readonly"));
            
            input = document.getElementById('true-readonly-text-input');
            console.log("\n'true-readonly-text-input' has attribute readonly : " + input.hasAttribute("readonly"));
            console.log("input element with ID 'true-readonly-text-input' attribute readonly value : " + input.getAttribute("readonly"));
            
            input = document.getElementById('false-readonly-text-input');
            console.log("\n'false-readonly-text-input' has attribute readonly : " + input.hasAttribute("readonly")
            + "\n\ninput element with ID 'false-readonly-text-input' attribute readonly value : " + input.getAttribute("readonly")
            + "\n\n'false-readonly-text-input' readOnly property value: " + input.readOnly );
            
            input = document.getElementById('editable-text-input');
            console.log("'editable-text-input' has attribute readonly : " + input.hasAttribute("readonly"));
            console.log("input element with ID 'readonly-text-input' attribute readonly value : " + input.getAttribute("readonly"));
            
            var c = document.getElementById("checkbox1");
            console.log("input element with ID 'checkbox1' has attribute readonly : " + c.hasAttribute("readonly"));
            console.log("input element with ID 'checkbox1' attribute readonly value : " + c.getAttribute("readonly"));
            c = document.getElementById("checkbox2");
            console.log("input element with ID 'checkbox2' has attribute readonly : " + c.hasAttribute("readonly"));
            console.log("input element with ID 'checkbox2' attribute readonly value : " + c.getAttribute("readonly"));
            console.log("checkbox2 'readOnly' property before readonly function call:" + c.readOnly);
            
            //Make the elements read-only
            readonly('#bool, #checkbox1, #checkbox2, #free, [name="radio-group"]', true);
            //Make the element read-only
            readonly("#reaonly_input", true);
            /**
             * @private
             * Toggles the readonly behaviours of elements with the following selector values:
             * #bool
             * #checkbox1
             * #checkbox2
             * #checkbox3
             * #free
             * #free2
             * [name="radio-group"]
             * #checkbox3
             * #readonly-text-input
             * #true-readonly-text-input
             * #false-readonly-text-input
             * #editable-text-input
             * #reaonly_input
             * #editable_bool
             * #editable_input'
             */
            function toggle() {
                var el, val, p, status, p2;
                    inputs = document.querySelectorAll('#bool, #checkbox1, #checkbox2, #checkbox3, #free, #free2, [name="radio-group"], #checkbox3, #readonly-text-input, #true-readonly-text-input, #false-readonly-text-input, #editable-text-input, #reaonly_input, #editable_bool, #editable_input');
                for (var i = 0, n = inputs.length; i < n; i++) {
                    el = inputs[i];
                    readonly(el, val = readonly.nativeSupportsReadOnly(el) ? !el.readOnly : !el.__readOnly__);
                    p = el.parentNode;
                    if ((p.nodeName||p.tagName).toLowerCase() === 'td') {
                        var tr = p.parentElement;
                        status = tr.children[tr.children.length - 1];
                        var ro = status.innerHTML === 'True';
                        status.innerHTML = ro ? 'False' : 'True';
                        status.setAttribute('class', ro ? 'editable' : 'read-only');
                    } else if (status=el.status) {
                        var s = status.innerHTML;
                        var ro = s === "editable (not read-only)";
                        el.status.innerHTML =  ro ? "read-only (not editable)" : "editable (not read-only)";
                        status.setAttribute('class', ro ? 'read-only' : 'editable');
                    }
                }
            }
            //bind toggle function to click event of the button
            document.getElementById("toggle-button").addEventListener('click', toggle);
            var chk = document.createElement('input');
            chk.type = 'checkbox';
            chk.id = "checkbox3";
            var btn = document.getElementById("toggle-button");
            btn.parentElement.parentElement.insertBefore(chk, btn.parentElement);
            var span = document.createElement('span');
            span.id = "checkbox3-text";
            span.innerHTML = "I am&nbsp;";
            btn.parentElement.parentElement.insertBefore(span, btn.parentElement);
            var span = document.createElement('span');
            span.id = "checkbox3-status-text";
            span.innerHTML = "editable (not read-only)";
            btn.parentElement.parentElement.insertBefore(span, btn.parentElement);
            console.log("chk has attribute readonly : " + chk.hasAttribute("readonly"));
            chk.status = span;
            c = document.getElementById("checkbox2");
            console.log("checkbox2 'readOnly' property after readonly function call:" + c.readOnly);
            console.log("readonly(c, false) execution");
            readonly(c, false);
            console.log("checkbox2 'readOnly' property new value:" + c.readOnly);
            

站长提示:
1. 苦力吧素材官方QQ群:950875342
2. 平台上所有素材资源,需注册登录会员方能正常下载。
3. 会员用户积极反馈网站、素材资源BUG或错误问题,每次奖励2K币
4. PHP源码类素材,如需协助安装调试,或你有二次开发需求,可联系苦力吧客服。
5. 付费素材资源,需充值后方能下载,如有任何疑问可直接联系苦力吧客服
相关资源 / 表单验证

JavaScript创建的自定义验证码生成器

一款纯js验证码生成器,鼠标点击生成按钮,即可随机生成字母和数字的组合验证码。
  表单验证
 1203  0

一款原生js表单验证特效代码

密码字段主要是判断字符长度;邮箱字段匹配是否包含@和. 有兴趣的可以学习!
  表单验证
 6416  0

jquery会员登录表单密码强度检测器

一款表单模块密码强度检测器,可实时检查html中的表单字段安全复杂性。
  表单验证
 6350  0

jquery集成多种类型表单验证插件

一款用于form多种类型字段表单验证器,包含:input文本框、select下拉菜单、checkbox复选框,以及email验证等。
  表单验证
 3329  0

评论数(0) 回复有机会获得K币 用户协议

^_^ 还没有人评论,快来抢个沙发!
😀
  • 😀
  • 😊
  • 😂
  • 😍
  • 😑
  • 😷
  • 😵
  • 😛
  • 😣
  • 😱
  • 😋
  • 😎
  • 😵
  • 😕
  • 😶
  • 😚
  • 😜
  • 😭
发表评论