【问题标题】:how can i make the multiple checkbox dropdown as checked我怎样才能使多个复选框下拉为选中状态
【发布时间】:2014-07-31 12:21:41
【问题描述】:
 <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)后检查checkbod的图像

希望值 aa 被检查,dd 被检查

【问题讨论】:

标签: android html cordova


【解决方案1】:

我会尝试使用 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>

通过类名检查更改 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()" />

【讨论】:

  • 你应该提供一些关于这个的描述!
  • 是的,我在 Krupa Patel 的 cmets 之后改变了它
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-02-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-11-09
相关资源
最近更新 更多