我想conastantly檢查值的變化。所以,如果用戶在輸入表格中選擇新的價值我想運行一些js代碼改變..校驗字段值與jQuery
<div class="select2-container country_to_state country_select" id="s2id_billing_country" style="width: 100%;">
<a href="javascript:void(0)" class="select2-choice" tabindex="-1">
<span class="select2-chosen" id="select2-chosen-1">Schweiz</span>
<abbr class="select2-search-choice-close" />
<span class="select2-arrow" role="presentation">
<b role="presentation"/>
</span>
</a>
<label for="s2id_autogen1" class="select2-offscreen">Land *</label>
<input class="select2-focusser select2-offscreen" type="text" aria-haspopup="true" role="button" aria-labelledby="select2-chosen-1" id="s2id_autogen1" />
</div>
<select name="billing_country" id="billing_country" class="country_to_state country_select " tabindex="-1" title="Land *" style="display: none;">
<option value="">Land auswählen…</option>
<option value="DE" selected="selected">Deutschland</option>
<option value="CH">Schweiz</option>
<option value="AT">Österreich</option>
</select>
我已經嘗試過目前爲止(不起作用)
$('#select2-chosen-1').change(function() {
alert("change");
});
我想同一個id問題。您可以更改編號 –
'因此,如果用戶在輸入表單中選擇了新值'但是您已經發布了與'span'元素相關的HTML標記,而不是'input'。因此,如果這是您的相關HTML標記,那麼您如何更改'span'內容? –
請檢查onchange事件是否存在span, – Robin