2010-12-01 62 views
0

我的頁面上有兩個表格:#add和#items。 #add有一行輸入。 #it​​ems有多行。我正在將輸入保存到數據庫中。 #add只能保存在按鈕上,而#items則會保存在模糊處。jQuery選擇器的問題,包括其他ID

問題是#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"); 
    } 
}); 
+0

很難說沒有看到你的HTML。 – 2010-12-01 18:15:54

+0

ID爲#add的表#items的子表嗎?另外,是否有可能擁有ID #items的另一個封裝元素? – Keith 2010-12-01 19:25:13

回答

1

這聽起來像你的選擇可能是撿了不正確的元素。嘗試在瀏覽器中的JavaScript控制檯中運行你的選擇:

$("#items tbody tr td input:not('[name=\"ext\"]')") 

然後,檢查返回的對象(或多個),並確保它們符合你想匹配的內容。