对字段值创建无限循环

发布于 2025-01-03 14:12:13 字数 1158 浏览 0 评论 0原文

所以我在 bigcartel 上创建了一家商店,我想添加免费送货选项。但他们目前不允许您将其添加到特定国家/地区。我目前正在添加编码以显示 div 或在用户的总额超过 85 英镑并且选择英国作为目的地时提醒用户。

ATM 我认为我的代码不会循环.. 好吧,它似乎不会:/ 我需要它循环,以便在客户添加或减去商品时检查总价的值..这将+或-总金额。

我已经

 var amount = {{ cart.total }} ;
 var country = {{ store.country | country_select }};

 t=setTimeout("checkprice()",10);

 function checkprice()
  {
 if(amount >= 85 || country = 45 )
 { 
   alert('OVER 85!') ;

  }
  else
  {
alert('monkeys')
  }
}

编辑了! 2012 年 2 月 8 日,

按照 @kolink 的建议:我想出了这个,,,

  //----get variables--
 var amount = {{ cart.total }};
 var moose = document.getElementById("country");

    function freedel() 
    {
      if (moose = 42 || amount >= 85 )  
    { 
        document.getElementById("moose").style.visibility='visible';     
     }
          else 
     {
      alert('WRONG!')
      }
      }

HTML 是:

        <div id="moose" style="visibility:hidden;"> dfgsdgfdsg</div>

    <h3 id="cart_price" onChange="freedel()">{{ cart.total | money_with_sign  }}</h3>

So im creating a shop on bigcartel and i want to add a free delivery option. but they currently dont allow you to add it to spercific countries. I am currently adding coding to show a div or alert the user when their total is over £85 and they select UK as their desitination.

ATM i think my code wont loop.. well it dont seem to :/
I need it to loop so that it checks the value of the total price when customers add or subtract items .. whicvh would + or - the total amount.

i HAVE

 var amount = {{ cart.total }} ;
 var country = {{ store.country | country_select }};

 t=setTimeout("checkprice()",10);

 function checkprice()
  {
 if(amount >= 85 || country = 45 )
 { 
   alert('OVER 85!') ;

  }
  else
  {
alert('monkeys')
  }
}

EDIT! 08/Feb/12

as suggested by @kolink: i have come up with this,,,

  //----get variables--
 var amount = {{ cart.total }};
 var moose = document.getElementById("country");

    function freedel() 
    {
      if (moose = 42 || amount >= 85 )  
    { 
        document.getElementById("moose").style.visibility='visible';     
     }
          else 
     {
      alert('WRONG!')
      }
      }

the HTML being:

        <div id="moose" style="visibility:hidden;"> dfgsdgfdsg</div>

and

    <h3 id="cart_price" onChange="freedel()">{{ cart.total | money_with_sign  }}</h3>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

予囚 2025-01-10 14:12:13

你告诉它在页面加载后 10 毫秒检查价格,然后你就永远不会告诉它再次运行。

如果您的代码有效,它会显示警报,然后再过 10 毫秒(这远远不够解决问题的时间)。

您应该做的是将 checkprice(); 添加到您的代码中,无论您在哪里更新 cart.totalstore.country。也许 onChange 事件可以帮助您。

附带说明一下,永远不要在 setTimeout 中使用字符串。传递函数本身(即 setTimeout(checkprice,10);)或匿名函数(即 setTimeout(function() {checkprice();},10); 相反。

You tell it to check the price 10 milliseconds after the page loads, then you never tell it to run again.

And if your code worked, it would show the alert, then another 10 milliseconds later (which is nowhere near enough time to fix the issue).

What you should do is add checkprice(); to your code wherever you update cart.total or store.country. Maybe an onChange event can help you there.

As a side note, never ever use a string in setTimeout. Pass the function itself (ie. setTimeout(checkprice,10);) or an anonymous function (is. setTimeout(function() {checkprice();},10); instead.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文