简体   繁体   English

Javascript值(如果选择了输入html)

[英]Javascript value if input html selected

I have an input html country and a script like this: 我有一个输入html country和一个像这样的脚本:

checkout.php Input html : checkout.php输入html:

<div class="col-md-6">
         <div class="form-group">
           <label for="country_shipping">Paese<sup>*</sup></label>
              <select class="form-control dark" id="country_ship" name="country_ship" tabindex="-1">

                    <option value="Afganistan">Afghanistan</option>
                    .... with all countries
              </select>
            </div>
</div>

My FIRST script: 我的第一个脚本:

<script> 

    $('#country_ship').change(function() {
      if($(this).val() == "Italy" 

        )
      {
         $('#price_ship').val('<?php echo $Italy;?>'); // it work well
         $('data-amount').val('{{ $total * 100 - $price_coupon * 100 + $Italy * 100 }}'); // it doesnt work well
         $('#total_ship').val('<?php echo number_format($total - $price_coupon + $Italy, 2);?>');  // it work well
      }
   });
</script>

My SECOND Script (button stripe): 我的第二个脚本(按钮条):

<script
                                    src="https://checkout.stripe.com/checkout.js" class="stripe-button"
                                    data-key="pk_test_yNuawoy0jUqj1GC14jwcQR5d"
                                    data-amount=""
                                    data-name="dixard"
                                    data-description="Widget"
                                    data-image="https://s3.amazonaws.com/stripe-uploads/acct_14s03fK9wMx3sd9Bmerchant-icon-1416180891533-icona.jpg"
                                    data-locale="auto"
                                    data-currency="eur"

                                    data-id="stripe"

                                    >
</script>

In my FIRST script i'm trying to give a value if user select country Italy , but it doesn't work! 在我的FIRST脚本中,如果用户选择国家Italy ,我想提供一个值,但是它不起作用! I would like attribute a value to "data-mount" with my operation. 我想通过我的操作将值赋给“数据装入”。

maybe I'm wrong here: 也许我在这里错了:

$('data-amount').val('{{ $total * 100 - $price_coupon * 100 + $Italy * 100 }}');

my variables like $total, $price_coupon, $italy exist and return the right values. 我的变量$ total,$ price_coupon,$ italy存在并返回正确的值。 i'm using "{{" because i'm using laravel blade template. 我使用的是“ {{”,因为我使用的是laravel刀片模板。

Thank your for your help! 感谢您的帮助!

$('data-amount') targets tag name. $('data-amount')以标签名称为目标。

if you want to target attribute , use 如果要定位属性 ,请使用

$('[data-amount]')

您还可以使用javascript更新属性data-amount量值,其中var point_val是要分配的值。

document.querySelector("script").setAttribute("data-amount",point_val);

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

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