jQuery .hide工作,但.show没有

d.l*_*a38 1 jquery show-hide

我有一个表,我需要显示和隐藏多达9 tr的一组3个组.我循环通过一个tr 9次生成所有9. .hide工作,但.show没有和中间的jquery没有中断(我已经将alert()全部放在代码中,甚至使用alert()来显示我想要显示或隐藏的参与者,并且值是正确的.

这是创建tr的片段

<cfloop index="i" from="1" to="9" step="1">


        <tbody id="attendeeRow<cfoutput>#i#</cfoutput>">
        <tr>
          <td colspan="2" bgcolor="#693505">
            <table width="600" border="0" align="center" cellpadding="4" cellspacing="0">
                <tr>
                  <td colspan="2">&nbsp;</td>
                </tr>
                <tr>
                  <td width="185" align="right">*Attendee <cfoutput>#i#</cfoutput> Name<br /></td>
                  <td><span id="sprytextfield100<cfoutput>#i#</cfoutput>">
                    <input name="attendeeName<cfoutput>#i#</cfoutput>" type="text" class="form" size="35" value="" />
                    <span class="textfieldRequiredMsg"></span></span></td>
                </tr>
                <tr>
                  <td align="right">*Attendee <cfoutput>#i#</cfoutput> Title<br /></td>
                  <td><span id="sprytextfield101<cfoutput>#i#</cfoutput>">
                    <input name="attendeeTitle<cfoutput>#i#</cfoutput>" type="text" class="form" size="35" value="" />
                    <span class="textfieldRequiredMsg"></span></span></td>
                </tr>
                 <tr>
                  <td align="right">*Attendee <cfoutput>#i#</cfoutput> Company</td>
                  <td><span id="sprytextfield102<cfoutput>#i#</cfoutput>">
                    <input name="attendeeCompany<cfoutput>#i#</cfoutput>" type="text" class="form" size="35" value="" />
                    <span class="textfieldRequiredMsg"></span></span></td>
                </tr>
                <tr>
                  <td align="right">*Attendee <cfoutput>#i#</cfoutput> Email</td>
                  <td><span id="sprytextfield103<cfoutput>#i#</cfoutput>">
                  <input name="attendeeEmail<cfoutput>#i#</cfoutput>" type="text" class="form" size="35" value="" />
                  <span class="textfieldRequiredMsg"></span><span class="textfieldInvalidFormatMsg"></span></span></td>
                </tr>

            </table>
          </td>
        </tr>
        </tbody>
        </cfloop>

        <!---- comment: this bottom part is what allows the user to show or hide the elements, I just use the div with an id="counter" to keep track of where I am.--->
        <tr>
            <td colspan="2" align="center" bgcolor="#693505" class="form">
                <div id="counter" style="visibility:hidden;">0</div>
                <div id="additional3">[+] Click here to register an additional 3 attendees</div>
                <div id="subtract3">[+] Click here to remove the last 3 attendees</div>
            </td>
        </tr>
Run Code Online (Sandbox Code Playgroud)

这是jquery;

$(document).ready(function () {

for (loopIndex = 1; loopIndex <= 9; loopIndex++)
{

    var currentRow = "attendeeRow" + loopIndex;

    var currentName = "attendeeName" + loopIndex;
    var currentTitle = "attendeeTitle" + loopIndex;
    var currentCompany = "attendeeCompany" + loopIndex;
    var currentEmail = "attendeeEmail" + loopIndex;



    $("#"+currentRow).hide();

    $("#"+currentName).val("--");
    $("#"+currentTitle).val("--");
    $("#"+currentCompany).val("--");
    $("#"+currentEmail).val("a@b.c");

}


$("#subtract3").hide(); 
$("#additional3").show();

$("#additional3").live("click", function(e) {

    e.preventDefault();

    var start = $("#counter").text(); 
    var increment = "3";
    var end = parseInt(start) + parseInt(increment); 


    for (loopIndex = start; loopIndex <= end; loopIndex++)
    {
        var currentRow = "attendeeRow" + loopIndex;

        var currentName = "attendeeName" + loopIndex;
        var currentTitle = "attendeeTitle" + loopIndex;
        var currentCompany = "attendeeCompany" + loopIndex;
        var currentEmail = "attendeeEmail" + loopIndex;

        alert("#"+currentRow);
        $("#currentRow").show();

        $("#"+currentName).val("");

        $("#"+currentTitle).val("");

        $("#"+currentCompany).val("");
        $("#"+currentEmail).val("");

    }
    $("#counter").text(end);
    if(start >= 6){
        $("#additional3").hide();

    }
    if(start >= 3){
        $("#subtract3").show();

    }

});

$("#subtract3").live("click", function(e) {

    e.preventDefault();

    var end = $("#counter").text(); 
    var increment = "3";
    var start = parseInt(start) - parseInt(increment); 


    for (loopIndex = start; loopIndex <= end; loopIndex++)
    {
        var currentRow = "attendeeRow" + loopIndex;

        var currentName = "attendeeName" + loopIndex;
        var currentTitle = "attendeeTitle" + loopIndex;
        var currentCompany = "attendeeCompany" + loopIndex;
        var currentEmail = "attendeeEmail" + loopIndex;



        $("#"+currentRow).hide();

        $("#"+currentName).val("--");
        $("#"+currentTitle).val("--");
        $("#"+currentCompany).val("--");
        $("#"+currentEmail).val("a@b.c");

    }
    $("#counter").text(start);


    if(start >= 6){
        $("#additional3").hide();

    }
    if(start >= 3){
        $("#subtract3").show();
    }

});
});
Run Code Online (Sandbox Code Playgroud)

小智 5

我假设这个......

alert("#"+currentRow);
$("#currentRow").show();
Run Code Online (Sandbox Code Playgroud)

就是这个......

alert("#" + currentRow);
$("#" + currentRow).show();
Run Code Online (Sandbox Code Playgroud)

您正在警告连接,但没有为DOM选择进行连接.

  • 那会做的大声笑.我花了太长时间,谢谢你,不是我 (2认同)