Javascript 选中复选框并在加载内容/页面上设置值

Javascript 选中复选框并在加载内容/页面上设置值,javascript,jquery,cart,Javascript,Jquery,Cart,我有一家商店。在购物车中(通常用户未登录时)是设置发票的复选框。如果未选中,则用户将获得账单 在下一步中,用户必须登录,并转到Procced页面。当用户继续操作时(登录页面之后),在不返回购物车的情况下无法更改复选框 我需要检查(登录后,在程序页面上)客户是公司还是普通用户(私人),如果用户是公司,则将发票设置为默认值 我有这样的密码: (我知道它不是纯粹的php——是某种框架) ?{foreach system.cart.options数据选项} ?{=option.title} ?{end

我有一家商店。在购物车中(通常用户未登录时)是设置发票的复选框。如果未选中,则用户将获得账单

在下一步中,用户必须登录,并转到Procced页面。当用户继续操作时(登录页面之后),在不返回购物车的情况下无法更改复选框

我需要检查(登录后,在程序页面上)客户是公司还是普通用户(私人),如果用户是公司,则将发票设置为默认值

我有这样的密码: (我知道它不是纯粹的php——是某种框架)


?{foreach system.cart.options数据选项}
?{=option.title}
?{endforeach}
//复选框的值为:toggleOption/facture
信息
?{foreach system.cart.options数据选项}
?{if true==option.option.enabled}
你拿到发票了吗
?{else}
你收到了吗
?{endif}
?{endforeach}
var isCompany=“?{=system.userLogged.InvoiceData.company}”;
var enablevoice=“?{=system.cart.invoiceEnabled}”;
如果(isCompany.lenght>0){
$.get(“${system.controllerUrl}setInvoiceEnabled”,函数(resp){
$.get(“${system.baseUrl}视图/启用发票”,函数(resp){
$(“#附加实现信息”).html(resp);
});
});
$.get(“${system.controllerUrl}切换选项/制作”,函数(resp){
});
}; 
//要检查选项的字符串:?{if system.cart.invoiceEnabled}
//system.baseURL/view/enableinvoice是一些代码,用于显示发票设置为默认值(当脚本工作时)


怎么了。它不起作用

乍一看,我会检查这行代码:

if (isCompany.lenght > 0) {
你拼错了长度。试试这个:

if (isCompany.length > 0) {
或者,根据“isCompany”变量的值是否为true/false,您可以将其写入

if (isCompany) { // check boolean value instead

希望有帮助

我更改了脚本,它可以工作,但只有在我重新加载/刷新页面之后

     <!-- CART PAGE before and after login -->

        var companyCustomer = "?{=system.userLogged.InvoiceData.company}";
        //If user is logged, companyCustomer has a value. If not = ""

        var enableInvoice = "?{=system.cart.invoiceEnabled}"; 
// If true = "1" , If false = "". That's not a boolean string. 

        var klik = $("#additionalRealizationInfo>label:first-child>input:checkbox");

        if (companyCustomer) {
            klik.prop('checked',  true);
            klik.prop("disabled", true);
            klik.css('cursor','default');             
    $.get("${system.controllerUrl}toggleOption/facture",function(resp){
             console.log(resp);       
                    });
                }; // End if (companyCustomer)



    <!-- PROCEED PAGE after login -->
        var companyCustomer = "?{=system.userLogged.InvoiceData.company}";
        //If user is logged, companyCustomer has a value. If not = ""

        var enableInvoice = "?{=system.cart.invoiceEnabled}"; 
// If true = "1" , If false = "". That's not a boolean string. 

        if (companyCustomer) {
            if (enableInvoice) {
               } else {
            $.get("${system.controllerUrl}toggleOption/facture",function(resp){
                console.log(resp);
                    });
                }; // end if (enableInvoice)
              };  // end if (companyCustomer)
我尝试了
.ready
.load()
.live()
但没有任何效果。已尝试通过
执行。单击
,但我不想要此方法。我不想在内容显示后也刷新页面

     <!-- CART PAGE before and after login -->

        var companyCustomer = "?{=system.userLogged.InvoiceData.company}";
        //If user is logged, companyCustomer has a value. If not = ""

        var enableInvoice = "?{=system.cart.invoiceEnabled}"; 
// If true = "1" , If false = "". That's not a boolean string. 

        var klik = $("#additionalRealizationInfo>label:first-child>input:checkbox");

        if (companyCustomer) {
            klik.prop('checked',  true);
            klik.prop("disabled", true);
            klik.css('cursor','default');             
    $.get("${system.controllerUrl}toggleOption/facture",function(resp){
             console.log(resp);       
                    });
                }; // End if (companyCustomer)



    <!-- PROCEED PAGE after login -->
        var companyCustomer = "?{=system.userLogged.InvoiceData.company}";
        //If user is logged, companyCustomer has a value. If not = ""

        var enableInvoice = "?{=system.cart.invoiceEnabled}"; 
// If true = "1" , If false = "". That's not a boolean string. 

        if (companyCustomer) {
            if (enableInvoice) {
               } else {
            $.get("${system.controllerUrl}toggleOption/facture",function(resp){
                console.log(resp);
                    });
                }; // end if (enableInvoice)
              };  // end if (companyCustomer)
enableInvoice = "";