zoukankan      html  css  js  c++  java
  • 绑定单/复选框和文本框

    绑定单/复选框和文本框

    /*
     * @param {string | object} box checkbox/radio的对象或者id
     * @param {string | object} input input的对象或者id
     */
     function bindBoxAndInput(box, input) {
         if (typeof box === 'string') {
             box = document.getElementById(box);
         }
         if (typeof input === 'string') {
             input = document.getElementById(input);
         }
         if (!box || !input) return;
    
         box.addEventListener('click', function() {
             if (box.checked) {
                 input.focus();
             } else {
                 input.value = '';
             }
         })
         input.addEventListener('input', function() {
             if (input.value.trim()) {
                 box.checked = true;
             } else {
                 box.checked = false;
             }
         })
     }
    
  • 相关阅读:
    npm改为淘宝镜像
    html中table中td内容换行
    git 切换文件夹路径
    git经常使用的命令
    day16
    day15
    day13
    day14
    day12
    day11
  • 原文地址:https://www.cnblogs.com/wangdapeng/p/6814476.html
Copyright © 2011-2022 走看看