zoukankan      html  css  js  c++  java
  • 单选框,复选框和下拉框回显赋值问题

    下拉菜单

    html:

    <tr>
    <td>是否销户</td>
    <td>
    <select name="brand.isexist">
    <option value="0">--已销户--</option>
    <option value="1">--在户--</option>
    </select>
    </td>
    </tr>

    jsp:

    是否销户
    <select name="brand.isexist" id="isexist">
    <option value="0">--已销户--</option>
    <option value="1">--在户--</option>
    </select>

    $("#isexist").val("${brand.isexist}");

    单选框

    html:

    <tr>
    <td>性别</td>
    <td><input type="radio" name="brand.gender" value="0" checked="checked">男
    <input type="radio" name="brand.gender"value="1">女
    </td>
    </tr>

    jsp:

    <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>

    性别
    <c:choose>
    <c:when test="${brand.gender==0 }">
    <input type="radio" name="brand.gender" value="0" checked="checked">男
    <input type="radio" name="brand.gender" value="1">女
    </c:when>
    <c:when test="${brand.gender==1 }">
    <input type="radio" name="brand.gender" value="0" >男
    <input type="radio" name="brand.gender" value="1" checked="checked">女
    </c:when>
    </c:choose>

    复选框:

    html:

    <tr>
    <td>习惯</td>
    <td><input type="checkbox" name="brand.hobby" value="吃饭" id="like">吃饭
    <input type="checkbox" name="brand.hobby" value="睡觉" id="like">睡觉
    <input type="checkbox" name="brand.hobby" value="打豆豆" id="like">打豆豆
    </td>
    </tr>

    jsp:

    //当页面加载完成的时候,自动调用
    /* var like = '${brand.hobby}';
    $("input[name='brand.hobby']").each(function(i,v){

    if(like.indexOf($(v).val())>=0)
    $(v).attr("checked","true")
    }); */

    window.onload=function(){
    //获取所有复选框
    var hobby = document.getElementsByName("brand.hobby");
    //获取字符串,替换防止出现空格
    var like = '${brand.hobby}'.replace(" ", ",");
    //去掉,号
    var pay = like.split(",");
    for(var i=0;i<hobby.length;i++){
    for(var j=0;j<pay.length;j++){
    //如果值与修改前的值相等
    if(hobby[i].value==pay[j]){
    hobby[i].checked = true;
    break;
    }
    }
    }
    };

  • 相关阅读:
    数据类型比较(==)
    uniapp(一)
    小程序分包
    小程序网易云(五)
    java.lang的详解
    有哪些日常节省时间的诀窍?
    怎么把知乎的回答转化成自己的知识?
    linux下搭建hadoop环境
    linux下,免密码登录
    mac下创建用户及赋予sudo权限
  • 原文地址:https://www.cnblogs.com/love1/p/7839740.html
Copyright © 2011-2022 走看看