2010-10-11 39 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