0

我遇到了我认为可能是一个简单的 JQuery 问题,但这让我很头疼。首先,我只写了几个星期的 JQuery,所以我的代码很弱。

基于选择选项和按钮单击,我显示了一些 HTML。显示的 HTML 具有按钮,也可以单击这些按钮来显示其他 HTML。我遇到的问题是,当我两次显示相同的“父 HTML”并单击按钮以显示“子 HTML”时,如果在添加第二个“父 HTML” 来自第一个父级的“子 HTML”被添加到第二个父级的“子 HTML”。我试图增加我的 id/class 变量来解决我的问题,但没有成功。

\$('#productbtn').live('click', function(e) {
(comtrinc++);
(ctierinc++);
if (\$('#prodselect option:selected').text() == "Commercial Attachments"){
\$('#my_table > tbody > tr').eq(14).after('<tr id="comattach0'+(comtrinc)+'"><td colspan=4>&nbsp;</td></tr><tr name="commercial" id="comattach1'+(comtrinc)+'"><td ALIGN=left colspan=4><input id="buttonremc'+(comtrinc)+'" type="button" style="width: 110px; height: 22px;" value="Remove Product">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font size=4><b><font color="#ADD8E6">Product: &nbsp;Commercial Attachments</b></font></td></tr><tr id="comattach2'+(comtrinc)+'"><td colspan=4>&nbsp;</td></tr><TR id="comattach3'+(comtrinc)+'"><td align=left><font color="#ADD8E6">Activity Type:</td><td align=left><select name="caacttype'+ (cainc++) +'" style="width:87px;"><option></option><option value="send">Send</option><option value="rec">Receive</option><option value="view">View</option></select></td><TD ALIGN=left><font color="#ADD8E6">Monthly Commission Percentage:</TD><TD ALIGN=left><input type="text" name="mthcom" maxlength=3 size=10 value="00"></TD><tr id="comattach4'+(comtrinc)+'"><td colspan=4>&nbsp;</td></tr><TR id="comattach5'+(comtrinc)+'"><TD ALIGN=left><font color="#ADD8E6">Annual Flat Rate:</TD><TD ALIGN=left><input type="text" name="afr'+ (afrinc++) +'" size=10 value="00.00" ></TD><TD ALIGN=left><font color="#ADD8E6">Monthly Flat Rate:</TD><TD ALIGN=left><input type="text" name="mfr'+ (mfrinc++) +'" size=10 value="00.00" ></TD><TR id="comattach6'+(comtrinc)+'"><TD ALIGN=left><font color="#ADD8E6">Monthly Flat Rate Attachment Limit:</TD><TD ALIGN=left><input type="text" name="mfral'+ (mfralinc++) +'" size=10 ></TD><TD ALIGN=left><font color="#ADD8E6">Excess Attachment Rate:</TD><TD ALIGN=left><input type="text" name="ear'+ (earinc++) +'" size=10 value="00.00" ></TD><tr id="comattach7'+(comtrinc)+'"><td colspan=4>&nbsp;</td></tr><TR id="comattach11'+(comtrinc)+'"><TD ALIGN=left><font color="#ADD8E6">Minimum Monthly Charge:</TD><TD ALIGN=left><input type="text" name="minmc'+ (minmcinc++) +'" size=10 value="00.00" ></TD><TD ALIGN=left><font color="#ADD8E6">Maximum Monthly Charge:</TD><TD ALIGN=left><input type="text" name="maxmc'+ (maxmcinc++) +'" size=10 value="00.00" ></TD><tr id="comattach15'+(comtrinc)+'"><td colspan=4>&nbsp;</td></tr><TR id="comattach8'+(comtrinc)+'"><TD ALIGN=left><font color="#ADD8E6">Per Attachment Rate:</td><TD ALIGN=left><input type="text" name="par'+ (parinc++) +'" size=10 value="00.00" ></TD><td colspan=2>&nbsp;</td><TR id="comattach10'+(comtrinc)+'"><TD ALIGN=left><font color="#ADD8E6">Maximum Allowed Attachment Pages:</TD><TD ALIGN=left><input type="text" name="maap'+ (maapinc++) +'" size=10 ></TD><TD ALIGN=left><font color="#ADD8E6">Excess Page Rate:</TD><TD ALIGN=left><input type="text" name="epr'+ (eprinc++) +'" size=10 value="00.00" ></TD><tr id="comattach12'+(comtrinc)+'"><td colspan=4>&nbsp;</td></tr><tr id="comattach13'+(comtrinc)+'"><TD ALIGN=left><font color="#ADD8E6">Per Page Rate:</TD><TD ALIGN=left><input type="text" name="ppr'+ (pprinc++) +'" size=10 value="00.00" ></TD><td colspan=2>&nbsp;</td><TR id="comattach14'+(comtrinc)+'"><TD ALIGN=left><font color="#ADD8E6">Minimum Submission Charge:</TD><TD ALIGN=left><input type="text" name="minsc'+ (minscinc++) +'" size=10 value="00.00" ></TD><TD ALIGN=left><font color="#ADD8E6">Maximum Submission Charge:</TD><TD ALIGN=left><input type="text" name="maxsc'+ (maxscinc++) +'" size=10 value="00.00" ></TD><tr class="comattach9'+(comtrinc)+'"><td colspan=4><input id="addtiercom'+(comtrinc)+'" type="button" style="width: 110px; height: 22px;" value="Add Tier"></td></tr>');


\$('#buttonremc').click(function() {
\$('#comattach0, #comattach1, #comattach2, #comattach3, #comattach4, #comattach5, #comattach6, #comattach7, #comattach8, .comattach9, #comattach10, #comattach11, #comattach12, #comattach13, #comattach14, #comattach15').remove();
})
var raisetierid = 1;
var rateplus = 1;
     var rangeplus = 1;
var catierrate = 1;
var rangemin = 1;
var rangemax = 1;

\$('#addtiercom'+(comtrinc)+'').live('click', function(e) {
\$('<tr id="commtier1'+(ctierinc)+'"><td colspan=4><input id="addnewtier'+(ctierinc)+'" type="button" style="width: 110px; height: 20px;" value="Add Tier" >&nbsp;&nbsp;<input id="removetiercom" type="button" style="width: 110px; height: 20px;" value="Remove Tier" ></td></tr><TR id="commtier2'+(ctierinc)+'"><TD ALIGN=left><font color="#ADD8E6">Tier Type</TD><TD ALIGN=left colspan=3>&nbsp;&nbsp;Attachments<input type="radio" name="brackettype" value="a">&nbsp;&nbsp;&nbsp;Pages<input type="radio" name="brackettype" value="p">&nbsp;&nbsp;&nbsp;Offices<input type="radio" name="brackettype" value="o"></TD><tr class="inctier'+(ctierinc) + (raisetierid++)+'"><TD ALIGN=left><font color="#ADD8E6">Tier '+ (rateplus++) +' Rate</TD><TD ALIGN=left><input type="text" name="catierrate'+ (catierrate++) +'" size=10 value="00.00" ></TD><TD ALIGN=left><font color="#ADD8E6">Tier '+ (rangeplus++) +' Range</TD><TD ALIGN=left><font color="#ADD8E6">Minimum&nbsp;<input type="text" name="rangemin'+ (rangemin++) +'" size=10 value="" ><font color="#ADD8E6">&nbsp;Maximum&nbsp;<input type="text" name="rangemax'+ (rangemax++) +'" size=10 value="" ></TD>').appendTo('.comattach9'+(comtrinc)+'');

\$('.comattach9'+(comtrinc)+'').hide();

\$('#addnewtier'+(ctierinc)+'').live('click', function(e) {
\$('<tr class="inctier'+(ctierinc) + (raisetierid++) +'"><TD ALIGN=left><font color="#ADD8E6">Tier '+ (rateplus++) +' Rate</TD><TD ALIGN=left><input type="text" name="catierrate'+ (catierrate++) +'" size=10 value="00.00" ></TD><TD ALIGN=left><font color="#ADD8E6">Tier '+ (rangeplus++) +' Range</TD><TD ALIGN=left><font color="#ADD8E6">Minimum&nbsp;<input type="text" name="rangemin'+ (rangemin++) +'" size=10 value="" ><font color="#ADD8E6">&nbsp;Maximum&nbsp;<input type="text" name="rangemax'+ (rangemax++) +'" size=10 value="" ></TD>').appendTo('.inctier'+(ctierinc)+'1');

})
4

1 回答 1

0

我相信这是一个身份冲突问题。我切换到按钮上的类并添加了一些 if、if else 条件循环以确定附加到 tr id 的变量值。

http://jsfiddle.net/JXeMS/30/

$
于 2013-03-22T02:56:32.880 回答