guyeuro
V2EX  ›  问与答

springmvc form:select 元素为何不能设置?

  •  
  •   guyeuro · Aug 14, 2017 · 1977 views
    This topic created in 3371 days ago, the information mentioned may be changed or developed.

    https://jsfiddle.net/6373j3k6/

    上面的 checkbox 打钩后,select 元素的值没有变,p 元素的 html 文字变空了 怎么回事啊?

     <select id="test">
      <option value="">请选择</option>
      <option value="1">选项一</option>
      <option value="2">选项二</option>
     </select>
    
     <input type="checkbox" id="flag" value="1"
       onchange="change(this, 'test')"/>  
      
     <p id="show">xx</p>
    

    function change(self, targetId) {
        if ($(self).is(':checked')) {
            $("#" + targetId).val("44");
            $("#" + targetId).attr("disabled", true);  
        }
        else {
            $("#" + targetId).attr("disabled", false);
        }
        
        $("#show").html($("#" + targetId).val());
    }
    
    3 replies  •  2017-08-14 17:05:49 +08:00
    jugelizi
    jugelizi
    Aug 14, 2017
    1
    44 对应的 option 又不存在 你获取的值当然没有
    guyeuro
    guyeuro
    OP
    Aug 14, 2017
    2
    @jugelizi 喔对的,现在的问题是设值不能传给 form:select 里的 path (这个关联 java 后台)
    guyeuro
    guyeuro
    OP
    Aug 14, 2017
    3
    @jugelizi 也就是用 select 选的可以传值,但是用这个 javascript 函数设的值就不能传给 path
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1959 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 47ms · UTC 01:55 · PVG 09:55 · LAX 17:55 · JFK 20:55
    ♥ Do have faith in what you're doing.