繁体   English   中英

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

[英]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

希望有帮助!

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

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

如何在加载时执行,以及如何动态更改/设置此切换选项? 当我没有选中CART PAGE中的复选框时,转到登录旁边,然后自动转到我得到的PROCEED PAGE

enableInvoice = "";

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM