select では、jquery を使用してプログラムでオプションを変更し、onchange アクションを呼び出したいと考えています。私はこのhtmlコードを持っています:
<select onchange="billing.newAddress(!this.value)" id="billing-address-select" name="billing_address_id">
<option value="1">value1</option>
<option value="2">value2</option>
<option value="3">value3</option>
</select>
そしてJavaScript:
jQuery(document).ready(function($) {
$('#billing-address-select').change(function(e){
if (sAddressType == 'school') {
$("#billing-address-select option[value='2']").attr("selected", "selected");
}
});
$('#billing-address-select').trigger('change');
})(jQuery);
したがって、実際には、条件が true の場合にページをロードした後、changein 'billing-address-select' を実行してから、onchange (billing.newAddress(!this.value)) アクションを呼び出します。しかし、このアクションは呼び出しません。どこが間違い?
私の英語でごめんなさい。ありがとう。