jQuery live() 和更改
我有一个困境 - 创建了一个行表,其中包含文本字段、下拉菜单和相关的第三个字段/选择。
还有“添加新”按钮,用于添加新行,并将默认值放置在这 3 个表单元素内。
这是根据从前面的选择菜单中选择的值更改第三列元素的脚本:
if ($('.navigation_type').length > 0) {
$('.navigation_type').live('change', function() {
var next_cell = $(this).parent('td').next();
var identity = $(this).attr('id').split('_');
var type = $(this).val();
var url = '/pages/c/navigation/a/fetch/id/' + identity[1] + '/type/' + type;
$.getJSON(url, function(data) {
if (!data.error) {
next_cell.html(data.content);
}
});
});
}
“添加新按钮”脚本如下所示:
if ($('.add_navigation').length > 0) {
$('.add_navigation').click(function() {
var master = $(this).attr('id').split('_');
master = master[1];
$.getJSON('/pages/c/navigation/a/newrow/master/' + master, function(data) {
$('#section_' + master).after(data.row);
});
return false;
});
}
“.add_navigation”按钮工作正常,直到我更改下拉菜单 - 它不执行任何操作 - 意味着第三列不会根据所选值而改变。
我使用了 live('change') 方法,因为我认为它应该解决问题,但显然我做错了什么 - 知道它是什么吗?
I have a dilema - created a table of rows which contain text field, dropdown menu and dependent 3rd filed / select.
There's also 'Add new' button which adds new row with default values placed withing these 3 form elements.
Here's the script which changes the third column element depending on the value selected from the preceding select menu:
if ($('.navigation_type').length > 0) {
$('.navigation_type').live('change', function() {
var next_cell = $(this).parent('td').next();
var identity = $(this).attr('id').split('_');
var type = $(this).val();
var url = '/pages/c/navigation/a/fetch/id/' + identity[1] + '/type/' + type;
$.getJSON(url, function(data) {
if (!data.error) {
next_cell.html(data.content);
}
});
});
}
And the 'Add new button' script looks like this:
if ($('.add_navigation').length > 0) {
$('.add_navigation').click(function() {
var master = $(this).attr('id').split('_');
master = master[1];
$.getJSON('/pages/c/navigation/a/newrow/master/' + master, function(data) {
$('#section_' + master).after(data.row);
});
return false;
});
}
The '.add_navigation' button works fine until the point where I change the value in the dropdown - it doesn't do anything - meaning the third column doesn't change depending on the selected value.
I've used live('change') menthod as I thought it should solve the problem, but clearly I'm doing something wrong - any idea what it is?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好的 - 问题已解决 - 是其他代码导致了问题!上面的脚本运行良好。
Ok - problem solved - it was the other code that was causing the problem! The script above works fine.