1. 程式人生 > >select標籤獲取值問題

select標籤獲取值問題

 <script>
        $(function () {
            $(".input_submit").click(function (e) {
                var type = $('#type').val();
                if (type == 0) {
                    alert('請選擇分類再提交');
                    return false;
                }
            });
        });
    </script>
<div class="input_box">
        <div class="input_box_title">所屬分類</div>
        <select id="type" class="input_box_select" name="info[type]">
            <option value="0">預設分類</option>
            {loop $types $v}
            <option value="{$v['id']}">{$v['name']}</option>
            {/loop}
        </select>
    </div>
 <tr>
            <td class="label">商品是否贈送積分</td>
            <td id="flag"><select name="goodsJf" id="test"  onchange="gradeChange()">
              <option value="0">請選擇...</option>
              <option value="1">普通商品</option>
              <option value="2">積分商品</option>
            </select></td>
          </tr>

          <script>
              function gradeChange(){
                  var objS = document.getElementById("test");
                  var value = objS.options[objS.selectedIndex].value;
                  if(value==2){
                      var oTest = document.getElementById("flag");
                      var newNode = document.createElement("span");
                      newNode.innerHTML = '&nbsp;<input id="flag2" type="text" placeholder="請輸入商品積分">';
                      oTest.appendChild(newNode);
                  }
                  else {
                      var elem=document.getElementById('flag2');
                      elem.parentNode.removeChild(elem)
                  }
              }
          </script>