如何选中多个复选框下拉列表

时间:2014-07-31 12:21:42

标签: android html html5 cordova

 <Select id="chkProduct" multiple="true" class="form_input1" placeholder="Product">
   <option selected disabled>Product</option> 
   </select>    


 $(function () {

    $(document).ready(function() {
     var hi = window.localStorage.getItem("rohil");

        $.ajax({
            type: "POST",
            contentType: "application/json; charset=utf-8",
           url: 'http://202.71.16.74/news/Service.svc/GetContactData',
            data: '{"ContactID":"' + hi +'"}',
            dataType: "json",
            processData: false,
            success: function (data) {

      $("#branchname").val(data.d.Data[0].BranchName);
       $("#add1").val(data.d.Data[0].Address1);
       $("#chkProduct").val(data.d.Data[0].Product);

            },
            error: function (result) {
                alert("Error");
            }
        });

    });
  });

上面是获取字符串中的值后我想要检查的图像复选框(即aa,dd,ee)

要检查值,要检查dd

1 个答案:

答案 0 :(得分:0)

我会尝试使用jquery来更改复选框状态。

   <script>
   $(document).ready(function(){//jQuery document function. Is called only once!     
       if(document.getElementById("string").innerHTML == 'smth'){
//Takes your string inner html- what you have written. 
           document.getElementById("myCheck1").checked = true; 
           document.getElementById("myCheck2").checked = true;
//makes your first and second checkbox checked
       }
    });
    </script>

通过classname检查更改document.getElementById的行:

       document.getElementsByClassName("check")[0].checked = true;
       document.getElementsByClassName("check")[1].checked = true;

仅当您的字符串已存在时才有效!否则你可以尝试添加onkeyup功能。

<script type="text/javascript">
 function myfunction() {
      //do smth
      return;
 }
</script>
<input type="text" name="foo" onKeyUp="return myfunction()" />