【发布时间】:2010-12-01 18:11:58
【问题描述】:
我的页面上有两个表格:#add 和#items。 #add 有单行输入。 #items 有多行。我正在将输入保存到数据库中。 #add 应该只在单击按钮时保存,而 #items 保存在模糊时。
问题是#add 输入也试图节省模糊。我在下面使用的选择器正在处理#add 表输入以及#items 表输入。
这是代码示例(如果需要,我可以链接到源文件):
$("#items tbody tr td input:not('[name=\"ext\"]')").live('focus',function() {
$(this).attr("readonly",false);
$(this).select();
curEdit = $(this).val();
var name = $(this).attr('name');
if (name == 'item') {
$(this).alphanumeric();
} else if (name == 'tag') {
$(this).alphanumeric({allow:" "});
} else if (name == 'desc') {
$(this).alphanumeric({allow:".,-()/ "});
} else if (name == 'qty') {
$(this).numeric();
} else if (name == 'cost' || name == 'list' || name == 'disc' || name == 'unit' || name == 'ext') {
$(this).numeric({allow:"."});
}
}).live('blur',function() {
$(this).attr("readonly",true);
if (curEdit != $(this).val()) { // only update on changes
var col = $(this).parent().prevAll().length;
var query = "action=edit&id="+$(this).parents('tr').attr('rel');
if (col == 1 || col == 10) { $(this).val($(this).val().toUpperCase()); } // format ITEM and GSA
if (col > 4 && col < 10) { $(this).val(formatCurrency($(this).val())); } // format COST, LIST, DISC, UNIT, and EXTENDED
if (col == 3) { $(this).val(ucEach($(this).val())); }
if (col > 3 && col < 10 && col != 5) {
var qty = $(this).parents('tr').find("[name='qty']").val();
var list = $(this).parents('tr').find("[name='list']").val();
var disc = $(this).parents('tr').find("[name='disc']").val();
if ($(this).attr('name') != "unit") {
var unit = formatCurrency(list * (1-(disc/100)));
$(this).parents('tr').find("[name='unit']").val(unit);
} else {
disc = formatCurrency(((list - $(this).val())/list)*100);
$(this).parents('tr').find("[name='disc']").val(disc);
}
unit = $(this).parents('tr').find("[name='unit']").val();
var ext = formatCurrency(qty * unit);
$(this).parents('tr').find("[name='ext']").val(ext);
query = query + "&field[]=qty&val[]="+qty+"&field[]=list&val[]="+list+"&field[]=unit&val[]="+unit+"&field[]=disc&val[]="+disc+"&field[]=ext&val[]="+ext;
} else {
query = query + "&field="+$(this).attr('name')+"&val="+$(this).val();
}
$.post("itemsdb.php", query, function(data) {
if (data.res == "fail") {
alert("There was a problem saving this item."+data.error);
}
},"json");
}
});
【问题讨论】:
-
不看你的html很难说。
-
你的表ID是#add表#items的子表吗?另外,您是否可能有另一个 ID 为 #items 的封装元素?
标签: jquery jquery-selectors css-selectors