gpt4 book ai didi

javascript - jQuery——无法更改用 AJAX 填充的选择框的值

转载 作者:行者123 更新时间:2023-11-30 05:41:46 44 4
gpt4 key购买 nike

我们网站的页面can be seen here问题与内容区域顶部的年份、品牌、型号小部件有关。选择年份、品牌、型号、子型号和引擎时...下一个下拉列表是零件类型,它的值(与其他值一样)通过 AJAX 填充。不幸的是,我正在尝试根据人员所属的类别设置此值,并且实际上将完全隐藏该字段。

我正在使用下面的代码来尝试这个——

jQuery('div.amfinder-horizontal td:nth-child(5) select').change(function () {
jQuery("div.amfinder-horizontal td:nth-child(7) select").append('<option value="0">Position</option>');
jQuery(this).parent().addClass('active');
jQuery(".popover").hide();
jQuery("#popover6").show();
jQuery("div.amfinder-horizontal td:nth-child(6) select option").each(function() { this.selected = (this.text == "Windshield Wiper Blade"); });
jQuery("div.amfinder-horizontal td:nth-child(6) select option").change();
// The following two lines are commands for a Prototype script, in place to simulate the change event
$('finder-4023--20454').simulate('click'); // This is the ID of the select element ( it is the same as div.amfinder-horizontal td:nth-child(6) select )
$('finder-4023--20454').simulate('change'); // This is the ID of the select element ( it is the same as div.amfinder-horizontal td:nth-child(6) select )
console.log('Changed!');
});

我相信正在发生的事情是发生了 AJAX 填充,然后更改事件试图在 AJAX 函数完成之前触发。 AJAX 在原型(prototype)脚本中,我不愿意更改它。相反,我想知道我是否可以简单地延迟更改并模拟事件一秒钟左右,以便 AJAX 填充可以完成。

请帮忙。 :-)

最佳答案

尝试将第一行替换为:

jQuery(document).on('change', 'div.amfinder-horizontal td:nth-child(5) select',function () {

这将适用于即使在代码被调用之后添加的元素,这是您使用 AJAX 呈现部分页面时必须具备的东西。

在此处阅读有关委托(delegate)事件的信息:http://api.jquery.com/on/

关于javascript - jQuery——无法更改用 AJAX 填充的选择框的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20410410/

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