使用jquery选中更改复选框 [英] Change checkbox checked using jquery

查看:64
本文介绍了使用jquery选中更改复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有下拉动态复选框,数据动态绑定。我通过cookie传递值,然后该值等于它检查的下拉复选框。例如

I have dropdown checkbox with data binded dynamically.I pass value through cookie then the value equal to the dropdown checkbox it checked.For example

$(document).ready(function () {
//binding dropdown checkbox code, after that

var cookievalue= getCookie("Cookieval");
        if (cookievalue!= null) {

            $(window).bind("load", function () {
                    $("input[id='dropdownchecklistid'][value='" + cookievalue+ "']").prop("checked", true);
                    
            });

        }
});



但是第一次加载页面时它不起作用



我尝试了什么:



我也试过window.load但是我没有得到合适的结果。第二次可能是在创建缓存之后。


But it doesn't work first time loading the page

What I have tried:

I have tried window.load also but I didn't get proper result.May be it works second time is after creating cache.

推荐答案

document )。ready( function (){
// 绑定下拉列表复选框代码,之后

var cookievalue = getCookie( Cookieval);
if (cookievalue!= null ){
(document).ready(function () { //binding dropdown checkbox code, after that var cookievalue= getCookie("Cookieval"); if (cookievalue!= null) {


window )。bind( load fun ction (){
(window).bind("load", function () {


input [id =' dropdownchecklistid'] [value =' + cookievalue + '])。prop( 选中 true );

});

}
});
("input[id='dropdownchecklistid'][value='" + cookievalue+ "']").prop("checked", true); }); } });



但是第一次加载页面时它不起作用



我尝试了什么:



我也试过window.load但是我没有得到合适的结果。第二次可能是在创建缓存之后。


But it doesn't work first time loading the page

What I have tried:

I have tried window.load also but I didn't get proper result.May be it works second time is after creating cache.


这篇关于使用jquery选中更改复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆