2010-12-01 5 views
0

내 페이지에 #add 및 #items 테이블이 두 개 있습니다. #add에는 단일 행의 입력이 있습니다. #items에 여러 행이 있습니다. 나는 입력을 데이터베이스에 저장하고있다. #add는 버튼을 클릭하면 저장되지만, #items는 흐리게 저장됩니다.다른 ID를 포함한 ID 별 jQuery selector 문제

문제는 #add 입력이 흐림 효과를 줄이려고한다는 것입니다. 아래에서 사용하는 선택기는 #item 테이블 입력뿐만 아니라 #add 테이블 입력에서도 작동합니다. 여기

코드의 샘플입니다 (필요하다면 나는 소스 파일에 링크 할 수 있습니다) : 당신의 선택이 잘못된 요소를 따기 수 있습니다처럼

$("#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을 보지 않고 말하기가 어렵습니다. –

+0

ID가 # #있는 테이블이 #items 테이블의 서브 테이블을 추가합니까? 또한 ID #items를 가진 또 다른 캡슐화 요소가있을 수 있습니까? – Keith

답변

1

그것은 소리. 브라우저의 자바 스크립트 콘솔에서 선택기를 실행 해보십시오 :

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

그런 다음, 반환되는 객체 (들)을 검사하고 그들은 당신이 일치시키고 자하는 내용과 일치하는지 확인하십시오.

+0

나는 selector를 firebug에 넣었고 테이블 parent div의 모든 것을 포함하고 있음을 발견했다. 위와 Keith의 의견 사이에 부모 div도 #items 인 것으로 나타났습니다. 나는 그것을 놓쳤다는 것을 믿을 수 없다. 모든 도움에 감사드립니다. – Greg

+0

도와 줘서 기쁩니다! 문제를 해결 한 답 옆의 녹색 확인 표시를 클릭하십시오. 스택 오버플로에 오신 것을 환영합니다! – ChessWhiz