2010-10-11 34 views
2

我有一個表,我使用下面的代碼動態地添加行到它中。有一個對話框,它有一個yes和no按鈕。問題是我需要通過該對話詢問一些事情。如果用戶說不,則會關閉對話並且該行將在j查詢的功能之後被添加。但是如果用戶選擇是,我需要使'au'的值爲one。默認值爲0.但是在這裏,在顯示彈出窗口之前,所有的行都會被創建,並且au將會是零。如何獲得特定的行和它的值。在此先感謝使用Jquery訪問特定行

$('#addItem').click(function() { 
           $('#dialog').dialog({ 
           autoOpen: true, 
           width: 400, 
           modal: true, 
           resizable: false, 
           buttons: { 
            "No": function() { 
             $(this).dialog("close"); 
            }, 
            "Yes": function() { 
             au = 1; 
             $(this).dialog("close"); 
            } 
           } 
          }); 
          $('#<%= tblEnergy.ClientID %> tr:last').after(
            "<tr>" 
            + "<td style='display:none'>" + getTextBoxValue('<%=ab.ClientID %>') + "</td>" 
            + "<td>" + $('#<%=ab.ClientID %> option:selected').text() + "</td>" 
            + "<td style='display:none'>" + getTextBoxValue('<%=txtBat.ClientID %>') + "</td>" 
            + "<td>" + getTextBoxValue('<%=txtReq.ClientID %>') + "</td>" 
            + "<td><span style='width:100%' class='del'><%= this.DelButtonHtml %></td>" 
            + "<td style='display:none'><span style='display:none'>" + getTextBoxValue('<%=hdfDept.ClientID %>') + "</span></td>" 
            + "<td style='display:none'><span style='display:none'>" + getTextBoxValue('<%=hdfLoc.ClientID %>') + "</span></td>" 
            + "<td style='display:none'><span style='display:none' class='clk'>" + au + "</span></td>" 
            + "</tr>" 
           ); 
           } 
           else { 

           } 
           setTextBoxValue('<%=txtStock.ClientID %>', ''); 
           setTextBoxValue('<%=txtBat.ClientID %>', ''); 
           setTextBoxValue('<%=txtReq.ClientID %>', ''); 
           setTextBoxValue('<%=ddlEnergy.ClientID %>', 0); 
          } 
          else { 
           showStatus(true, "Please specify the Required Quantity"); 
          } 
         } else { 
          showStatus(true, "Please specify the Required Quantity"); 
         } 
        } 
       }); 

settextBox和gettextbox是用戶自定義的JavaScript函數來設置或形式獲取值

回答

2

您在上面給出的代碼是不完整的語法,所以我切出該行我認爲這與問題無關。所以這裏的答案僅僅是對話框中回調函數可以做什麼的一個指導。有了前言,這裏是代碼:

$('#addItem').click(function() { 
    $('#dialog').dialog({ 
     autoOpen: true, 
     width: 400, 
     modal: true, 
     resizable: false, 
     buttons: { 
      "No": function() { 
       addDynamicRow(0); 
       $(this).dialog("close"); 
      }, 
      "Yes": function() { 
       addDynamicRow(1); 
       $(this).dialog("close"); 
      } 
     } 
    }); 
}); 


function addDynamicRow(auValue) { 
    $('#<%= tblEnergy.ClientID %> tr:last').after(
     "<tr>" 
     + "<td style='display:none'>" + getTextBoxValue('<%=ab.ClientID %>') + "</td>" 
     + "<td>" + $('#<%=ab.ClientID %> option:selected').text() + "</td>" 
     + "<td style='display:none'>" + getTextBoxValue('<%=txtBat.ClientID %>') + "</td>" 
     + "<td>" + getTextBoxValue('<%=txtReq.ClientID %>') + "</td>" 
     + "<td><span style='width:100%' class='del'><%= this.DelButtonHtml %></td>" 
     + "<td style='display:none'><span style='display:none'>" + getTextBoxValue('<%=hdfDept.ClientID %>') + "</span></td>" 
     + "<td style='display:none'><span style='display:none'>" + getTextBoxValue('<%=hdfLoc.ClientID %>') + "</span></td>" 
     + "<td style='display:none'><span style='display:none' class='clk'>" + auValue + "</span></td>" 
     + "</tr>" 
    ); 
} 
+0

這個答案幫助嗎? – 2010-10-12 10:55:15

+0

think弗洛伊德粉紅色:) – kbvishnu 2010-10-15 06:20:57