我有这样的html和js(带有jquery)代码:
<label>Nationality</label>
<select name="user_nationality" class="input">
<option value="1" selected onclick="$('#userphonearea').val('+62');">Indonesia</option>
<optgroup label="Other Countries">
<option value="2" onclick="$('#userphonearea').val('+44');">United Kingdom</option>
<option value="3" onclick="$('#userphonearea').val('+1');">United States of America</option>
</optgroup>
</select>
<label>Phone Number</label>
<input type="text" name="user_phone_area" id="userphonearea" maxlength="5" size="5" value="" placeholder="+" required />
<input type="text" name="user_phone_number" maxlength="30" size="10" required />
如果我选择user_nationality,我想自动输入user_phone_area。我使用了onclick,它适用于桌面浏览器。但它不适用于 android 或 iphone 等移动浏览器。
我尝试使用 OnSelect 更改 OnClick,但它不适用于桌面和移动设备
<select name="user_nationality" class="input">
<option value="1" selected onselect="$('#userphonearea').val('+62');">Indonesia</option>
<optgroup label="Other Countries">
<option value="2" onselect="$('#userphonearea').val('+44');">United Kingdom</option>
<option value="3" onselect="$('#userphonearea').val('+1');">United States of America</option>
</optgroup>
</select>