如果由 JQuery 添加,则选择不会触发的更改
我有一个多级选择链,其中第一个选择的值生成下一个选择列表的选项。在第二个列表中,某些值将导致 div 与另一个输入一起显示。
在静态内容上测试时,我的代码(如下)似乎工作得很好(即:第二个选择是硬编码在 html 中)。但是当我用 JQuery 添加它时,第二级不再触发 .change 函数。
<script type="text/javascript">
$(document).ready(function() {
$dts = $("select[name='tourdes']");
$dts.change(function() {
var dtsValue = $(this).val();
var dtsString = '?tourdes=' + dtsValue;
$('#dateSelect').show();
$('#dateSelect').load('include/avdates.php' + dtsString).append();
});
});
</script>
<script type="text/javascript">
$(document).ready(function() {
$tags = $("select[name='tourcode']");
$tags.change(function() {
if ($(this).val() == "private") {
$(".prvcal").css({"visibility":"visible"});
}
});
});
</script>
我猜测有些东西需要重新初始化,但我的实验没有得到任何结果。
I have a multi level select chain, where by the value of the first select generates the options for the next select list. And within the second list some of the values will cause a div to display with another input.
My codes (below) seem to work just fine when tested on static content (ie: the second select is hard coded in the html). But when I add it with JQuery, the second level no longer triggers the .change function.
<script type="text/javascript">
$(document).ready(function() {
$dts = $("select[name='tourdes']");
$dts.change(function() {
var dtsValue = $(this).val();
var dtsString = '?tourdes=' + dtsValue;
$('#dateSelect').show();
$('#dateSelect').load('include/avdates.php' + dtsString).append();
});
});
</script>
<script type="text/javascript">
$(document).ready(function() {
$tags = $("select[name='tourcode']");
$tags.change(function() {
if ($(this).val() == "private") {
$(".prvcal").css({"visibility":"visible"});
}
});
});
</script>
I am guessing something needs to be re-initialized, but I am getting no where with my experiments.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您使用的是 jQuery 1.7,则需要使用
on
,因为live
和delegate
均已弃用。on() 文档
If you're using jQuery 1.7 you'll want to use
on
, as bothlive
anddelegate
are deprecated.docs for on()
您可能正在使用动态生成的 HTML 元素。如果是这种情况,您需要使用
.delegate()
来处理它们:You are probably using dynamically-generated HTML elements. If that is the case, you need to use
.delegate()
to handle them: