JavaScript OnClick Select标记不';不能在移动浏览器上工作

JavaScript OnClick Select标记不';不能在移动浏览器上工作,javascript,jquery,select,onclick,onselect,Javascript,Jquery,Select,Onclick,Onselect,我有如下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

我有如下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 />
国籍
印度尼西亚
大不列颠联合王国
美利坚合众国
电话号码
如果我选择用户国籍,我想自动输入用户电话区。 我使用了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>

印度尼西亚
大不列颠联合王国
美利坚合众国

找到了我自己问题的答案

<select name="user_nationality" id="changecountry" class="input">
<option value="1" phonecode="+62">Indonesia</option>
<optgroup label="Other Countries">
    <option value="2" phonecode="+44">United Kingdom</option>
    <option value="3" phonecode="+1">United States of America</option>
</optgroup>

印度尼西亚
大不列颠联合王国
美利坚合众国


$('#changecountry')。on('change',function(){
var phonecode=$('option:selected',this).attr('phonecode');
$('#userphonearea').val(电话编码);
});

这在许多浏览器中都不起作用,您应该将EventHandler附加到
选择
本身,而不是
选项
s。
<script>
$('#changecountry').on('change', function() {
    var phonecode = $('option:selected', this).attr('phonecode');
    $('#userphonearea').val(phonecode);
});
</script>