gpt4 book ai didi

jquery - 使用 jQuery 和 Ajax 填充第二个下拉列表

转载 作者:行者123 更新时间:2023-12-01 05:03:41 25 4
gpt4 key购买 nike

我正在尝试根据外部 html 文件中第一个下拉列表的值填充第二个下拉列表,该文件仅填充了选项。

外部文件示例:

<option value="Bedfordshire">Bedfordshire</option>
<option value="Berkshire">Berkshire</option>
<option value="Buckinghamshire">Buckinghamshire</option>

第一个下拉值的示例:

 <select>
<option value="GB">UNITED KINGDOM</option> //option to load drop-GB.html
<option value="US">UNITED STATES</option> //option to load drop-US.html
</select>

在 FF/Safari/Chrome 中一切正常,但在 IE 或 iPad 中却完全不行?

var $shipcountry = $('#ShippingCountry');
$ShippingStateSelect = $('#ShippingStateSelect');
$ShippingStateSelect.load('drop-GB.html'); //pre load default list

$shipcountry.change(function () {
var countryName = $shipcountry.val();

$.ajax({
type: 'GET',
url: 'drop-' + countryName + '.html',
success: function (msg) {
$ShippingStateSelect.load('drop-' + countryName + '.html');
//fire other events on page
},
error: function (msg) {
$ShippingStateSelect.hide();
//show error message here
},

});

});

最佳答案

您没有对传入的 HTML 进行排序,并且由于它不是“纯”元素,因此 IE 会失败,而 Firefox/Chrome 等会尝试修复它。

您的 drop-US.html 包含类似

的 HTML 结构
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<!-- BC_OBNW -->
<head>
<title>drop-US</title>
<link href="/StyleSheets/ModuleStyleSheets.css" type="text/css" rel="StyleSheet" />
<script type="text/javascript">var jslang='EN';</script>
</head>

然后它尝试将其插入选择框。

所以你应该在ajax请求中过滤掉它,或者在源代码中删除它。 :)

关于jquery - 使用 jQuery 和 Ajax 填充第二个下拉列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7752818/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com