选中复选框并在加载时设置值 content/page

Check checkbox and set value on load content/page

我有一家店。在购物车中(通常用户未登录时)是设置发票的复选框。如果未选中 - 那么用户会收到账单。

下一步,用户必须登录,然后转到已处理页面。当用户继续(登录页面后)时,如果不返回购物车则无法更改复选框。

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

我有那个代码: (我知道不是纯的php——是某种框架)

<!-- CART PAGE with checkbox -->
<div id="additionalRealizationInfo">
    ?{foreach system.cart.optionsData option}
        <label>
        <input class="additionalRealizationInfoCheckbox" 
                                       type="checkbox"  
                                       ?{if  true == option.option.enabled}
                                       checked="checked"
                                       ?{endif}
                                       name="additional?{=system.randomNumber}" 
                                       value="${system.controllerUrl}ToggleOption/?{=option.name}" />
                                       ?{=option.title}
        </label>
?{endforeach}


// The Value of checkbox is: toggleOption/facture






<!-- PROCCED PAGE without checkbox - On this page, after login, user see own choice from cart before login -->

<div id="additionalRealizationInfo">
    <h2>Infos</h2>
        <div>
        ?{foreach system.cart.optionsData option}
            <div>
            ?{if  true == option.option.enabled}
               You get Invoice
            ?{else}
                You get recive
            ?{endif}
        </div>
        ?{endforeach}
        </div>
</div>

<script type="text/javascript"> 
var isCompany = "?{=system.userLogged.InvoiceData.company}"; <!-- Company Name -->
var enableInvoice = "?{=system.cart.invoiceEnabled}";

if (isCompany.lenght > 0) {
    $.get("${system.controllerUrl}setInvoiceEnabled",function(resp) {
        $.get("${system.baseUrl}view/enableinvoice",function(resp) {
            $("#additionalRealizationInfo").html(resp);
            });
     });
     $.get("${system.controllerUrl}toggleOption/facture",function(resp) {
      });
  }; 
</script>

// string to check choice: ?{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

希望对您有所帮助!

我更改了脚本并且它起作用了,但只有在我 reload/refresh 一个页面之后。

     <!-- 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)

它如何在加载时执行,并且动态地 change/set 这个切换选项? 当我没有选中 CART PAGE 中的复选框时,转到登录旁边,然后自动转到 PROCEED PAGE 我得到

enableInvoice = "";

我尝试了.ready.load().live(),但没有任何效果。尝试通过 .click 执行,但我不想要这种方法。我不想在内容显示后也刷新页面。