我继承了这个代码,该代码在我的在线结帐中填充了国家/地区。显示的第一个值是澳大利亚,但我需要将其设置为美国。
<script type=“text/javascript”>
$(function(){
$('#FormField_11>option, #FormField_21>option').each(function () {
// PUT THE COUNTRIES YOU WANT TO KEEP IN THE LIST HERE
var countries = [ 'United States', 'Canada', 'Belgium', 'Australia', 'Denmark', 'Finland', 'Germany', 'Ireland', 'Italy', 'Japan', 'Netherlands', 'Netherlands Antilles', 'New Zealand', 'Norway', 'Sweden', 'United Kingdom', 'Austria' ];
var country = $(this).text();
if (countries.indexOf(country) == -1) {
$(this).remove();
}
});
});
</script>
谁能帮我将美国定义为默认值?
提前致谢
最佳答案
删除所有不需要的国家后,将下拉列表的值设置为所需的默认值:
$(function(){
$('#FormField_11>option, #FormField_21>option').each(function () {
// PUT THE COUNTRIES YOU WANT TO KEEP IN THE LIST HERE
var countries = [ 'United States', 'Canada', 'Belgium', 'Australia', 'Denmark', 'Finland', 'Germany', 'Ireland', 'Italy', 'Japan', 'Netherlands', 'Netherlands Antilles', 'New Zealand', 'Norway', 'Sweden', 'United Kingdom', 'Austria' ];
var country = $(this).text();
if (countries.indexOf(country) == -1) {
$(this).remove();
}
});
$("#FormField_11, #FormField_21").value("United States");
});
关于javascript - 我需要为 javascript 数组设置默认选项(下拉字段),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58400700/