我有一个带有呼号的国家/地区列表,我希望通过在列表中选择一个国家/地区,对应于该国家/地区的指示符放在我的输入中但是它不起作用...我找不到解决方案
<script type="text/javascript">
var mytextbox = document.getElementById('Recipient');
var mydropdown = document.getElementById('indicatif');
mydropdown.onchange = function(){
mytextbox.innerHTML = this.value;
}
</script>
<select style="visibility:hidden;" style="color:black;" id="indicatif">
<option value="">Destination country</option>
<option value="+355">Albania</option>
<option value="+213">Algeria</option>
<option value="+376">Andorra</option>
<option value="+244">Angola</option>
<option value="+1264">Anguilla</option>
<option value="+1268">Antigua and Barbuda</option>
<option value="+54">Argentina</option>
<option value="+374">Armenia</option>
<option value="+297">Aruba</option>
<option value="+61">Australia</option>
<option value="+43">Austria</option>
<option value="+994">Azerbaijan</option>
<option value="+1242">Bahamas</option>
....
</select>
<input style="color:black;" name="Recipient" id="Recipient" type="text">
答案 0 :(得分:3)
var mytextbox = document.getElementById('Recipient');
var mydropdown = document.getElementById('indicatif');
mydropdown.addEventListener('change', function(){
mytextbox.value = mydropdown.value;
});
<select style="color:black;" id="indicatif">
<option value="">Destination country</option>
<option value="+355">Albania</option>
<option value="+213">Algeria</option>
<option value="+376">Andorra</option>
<option value="+244">Angola</option>
<option value="+1264">Anguilla</option>
<option value="+1268">Antigua and Barbuda</option>
<option value="+54">Argentina</option>
<option value="+374">Armenia</option>
<option value="+297">Aruba</option>
<option value="+61">Australia</option>
<option value="+43">Austria</option>
<option value="+994">Azerbaijan</option>
<option value="+1242">Bahamas</option>
....
</select>
<input style="color:black;" name="Recipient" id="Recipient" type="text">
完整的代码段,只需将其复制并粘贴到您的项目中即可。
<html>
<head>
<title>HelloWorld</title>
</head>
<body>
<select style="color:black;" id="indicatif">
<option value="">Destination country</option>
<option value="+355">Albania</option>
<option value="+213">Algeria</option>
<option value="+376">Andorra</option>
<option value="+244">Angola</option>
<option value="+1264">Anguilla</option>
<option value="+1268">Antigua and Barbuda</option>
<option value="+54">Argentina</option>
<option value="+374">Armenia</option>
<option value="+297">Aruba</option>
<option value="+61">Australia</option>
<option value="+43">Austria</option>
<option value="+994">Azerbaijan</option>
<option value="+1242">Bahamas</option>
</select>
<input style="color:black;" name="Recipient" id="Recipient" type="text">
<script>
var mytextbox = document.getElementById('Recipient');
var mydropdown = document.getElementById('indicatif');
mydropdown.addEventListener('change', function() {
mytextbox.value = mydropdown.value;
});
</script>
</body>
</html>
答案 1 :(得分:1)
试试这个:
getBounds()