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

jquery针对email电子邮箱表单验证

jq+css3结合的一款邮箱验证,用户的动作分别呈现了三种不同动画效果,大家可以试试!
  表单验证
 214  

jquery轻量级会员注册表单步骤向导插件

multiStepForm是一个非常小(缩小了约1kb)的jquery插件,它可将多字段表单转换为按步骤显示填写的表单模块,从而提升更好的用户体验。非常适合注册/表单信息登记。
  表单验证
 586  

jquery弹出层显示实时输入密码检测规则插件

一款实时密码检测工具插件,可根据自定义密码规则,在线实时检测当前输入的密码是否符合规范。
  表单验证
 171  

jquery多种字段类型的表单验证

超实用的表单验证插件,含:用户名、电话、密码、邮箱、网址、身份证等字段类型。
  表单验证
 221  

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

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