guyeuro
V2EX  ›  问与答

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

  •  
  •   guyeuro · Aug 14, 2017 · 1739 views
    This topic created in 3222 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
        1
    jugelizi  
       Aug 14, 2017
    44 对应的 option 又不存在 你获取的值当然没有
    guyeuro
        2
    guyeuro  
    OP
       Aug 14, 2017
    @jugelizi 喔对的,现在的问题是设值不能传给 form:select 里的 path (这个关联 java 后台)
    guyeuro
        3
    guyeuro  
    OP
       Aug 14, 2017
    @jugelizi 也就是用 select 选的可以传值,但是用这个 javascript 函数设的值就不能传给 path
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5458 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 31ms · UTC 07:47 · PVG 15:47 · LAX 00:47 · JFK 03:47
    ♥ Do have faith in what you're doing.