2016-10-03 71 views
0

我有兩個input字段。一種是隱藏式的(我現在已經把它做成了一種文本類型)並且動態地獲取它的值。取決於此值,我將顯示具有該值的alert,並在其他input字段後顯示一些特定信息。當輸入字段值發生變化時啓動一個函數 - jQuery

假設input字段首先有一個table_rate:38的值(值也可以是空的)。現在問題開始了。當input字段的值更改爲table_rate:23時,應該出現alert,並且應該在其他input字段之後顯示信息。但它不起作用。

在這裏您可以將HTML:

<p class="form-row form-row form-row-wide address-field validate-required validate-postcode form-row-first woocommerce-validated" id="billing_postcode_field" data-o_class="form-row form-row form-row-wide address-field validate-required validate-postcode"> 
    <label for="billing_postcode" class=""> 
     Postnummer 
     <abbr class="required" title="påkrevet">*</abbr> 
    </label> 
    <input type="text" class="input-text " name="billing_postcode" id="billing_postcode" placeholder="Postnummer" value="" autocomplete="off"> 
</p> 

<input type="text" name="shipping_method[0]" data-index="0" id="shipping_method_0" value="table_rate:38" class="shipping_method"> 

Here你可以看到完整的jsfiddle。

我該如何解決這個問題?

感謝您的幫助!

+0

問題是在if語句中,嘗試像這樣:if(zone =='table_rate:33')帶雙等號並且它將起作用 – rosuandreimihai

+0

感謝您的評論,但這並不奏效,恐怕。 –

回答

0

您需要明確trigger您的setInterval方法中的更改。

setInterval(function(){ 
    $('#shipping_method_0').val('table_rate:23'); 
    $('#shipping_method_0').trigger("change"); // after updating the input, trigger 'change' event 
}, 1000); 

Updated Fiddle

0

嘿試試這個jQuery希望它可以幫助你

<script> 
$(document).ready(function(){  
$('.shipping_method').on('change', function() { 
alert("your value changed To " + this.value); 
}) 
}); 
</script> 
0

請找到更改撥弄之下,正如我剛纔所說

if (zone == 'table_rate:38') { 
    $("#billing_postcode").after("<span id='contenttoshow'>Varene vil bli levert til:<br>" + 
     "Sped trans, " + 
     "Titangaten 11, " + 
     "1630 Gamle Fredrikstad<br></span>"); 
} 

https://jsfiddle.net/dLo472bs/13/

相關問題