• Mui-js获取复选框的值,利用数组


    <!DOCTYPE html>
    <html>
        <head>
            <meta charset="utf-8">
            <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
            <title></title>
            <script src="js/mui.min.js"></script>
            <link href="css/mui.min.css" rel="stylesheet" />
            <script type="text/javascript" charset="utf-8">
                mui.init();
            </script>
    
        </head>
    
        <body>
            <header class="mui-bar mui-bar-nav">
                <!--顶部导航栏-带返回键-->
                <a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
                <h1 class="mui-title">测试属性checkbox</h1>
            </header>
            <div class="mui-content">
                <div class="mui-input-row mui-checkbox mui-left"><!--mui-left表示复选框在左侧-->
                    <label>王者</label>
                    <input name="checkbox1" value="王者" type="checkbox"  class="rds"><!--checked="checked"默认选中;class="rds"方便获取dom节点-->
                </div>
                <div class="mui-input-row mui-checkbox mui-left"><!--mui-radio单选框-->
                    <label>搬砖</label>
                    <input name="checkbox1" value="搬砖" type="checkbox" class="rds"><!--注意单选框的name必须一致,表示是一个组内的选项-->
                </div>
                <button type="button" onclick="getVals();">获取值</button>
            </div>
            <script type="text/javascript">
                function getVals(){
                    var res = getRadioRes('rds');
                    if(res.length < 1){
                        mui.toast('请选择');
                        return;
                    }
                    mui.toast(res);
                }
                function getRadioRes(className){
                    var rdsObj = document.getElementsByClassName(className);/*获取值*/
                    /*alert(rdsObj.length);测试一下找到几个节点*/
                    var checkVal = new Array();
                    var k = 0;
                    for(i = 0; i< rdsObj.length; i++){
                        if(rdsObj[i].checked){
                            checkVal[k] = rdsObj[i].value;
                            k++;
                        }
                    }
                    return checkVal;
                }
            </script>
        </body>
    
    </html>

  • 相关阅读:
    springboot
    POI/JFreeChart
    ssm(6)spring-test
    DBUtils与BeanUtils
    数据连接池C3P0/DBCP/DRUID/自定义连接池
    web核心(3)响应头请求头状态码及dns解析过程
    log4j/Logback/SLF4j
    ssm(4)整合
    列表字典元组方法
    第四天 Python基础语法 编码规范 变量
  • 原文地址:https://www.cnblogs.com/fdxjava/p/11072098.html
Copyright © 2020-2023  润新知