English 中文(简体)
Count dynamic
原标题:Counting the number of dynamically added divs in jquery
  • 时间:2012-01-12 15:25:04
  •  标签:
  • php
  • jquery

I m new to JQuery so I m possibly doing this completely wrong. I want to count the number of divs there are within another div as I dynamically add to them. There are already several divs there already. Basically what I do is click a button, it adds a new div and alerts the total number of divs, the old plus the new. This is what I have so far and it s not working. Here s the Jquery:

<!-- Jquery to Add New Textarea -->

<script type="text/javascript">

    $(document).ready(function(){

        $( #addTertButton ).click(function(){

            //Shows 
            alert($( div.addTertDiv ).size());

            $( .addTertDiv ).append("<?php echo $tertDiv; ?>");

        });
    });
</script>

这里是:

                    <div class="docedcont">
                        <div class="tertiarywrapper">
                            <?php

                                $counttert = count($this_rds->tertiary_array);
                                for($i = 0; $i < $counttert; ++$i) {
                                    echo("<div id= tertiaryselect >");


                                        echo("<br />".$this_rds->rds_number.".".$this_rds->physreq_number.".".$this_rds->tertiary_array[$i][ tertiary_number ]." ".$this_rds->tertiary_array[$i][ tertiary_title ]."<br /><br />");

                                        echo("<textarea name="tertiary_text-".$i."" cols="50" rows="10" class="dark" onfocus="this.className= light " onblur="this.className= dark ">");

                                            echo $this_rds->tertiary_array[$i][ tertiary_text ];

                                        echo("</textarea>");

                                        echo("<input name="tertiary_id-".$i."" type="hidden" value="".$this_rds->tertiary_array[$i][ tertiary_id ]."">");
                                        echo("<input name="tertiary_type-".$i."" type="hidden" value="gb,ie,in,ae">");
                                        echo("<input name="tertiary_number-".$i."" type="hidden" value="".$this_rds->tertiary_array[$i][ tertiary_number ].""> ");
                                        echo("<input name="tertiary_physreqlink_id-".$i."" type="hidden" value="".$this_rds->tertiary_array[$i][ tertiary_physreqlink_id ]."">");
                                        echo("<input name="tertiary_modby-".$i."" type="hidden" value="".$this_rds->tertiary_array[$i][ tertiary_modby ]."">");
                                        echo("<input name="tertiary_moddate-".$i."" type="hidden" value="".$this_rds->tertiary_array[$i][ tertiary_moddate ]."">");

                                        //Subsection Publish Checkbox
                                        echo("Publish Subsection");
                                        if ($this_rds->tertiary_array[$i][ tertiary_show ]=="yes"){
                                            echo("<input name="tertiary_show-".$i."" type="checkbox" value="yes" checked />");
                                        }
                                        else {
                                            echo("<input name="tertiary_show-".$i."" type="checkbox" value="no" />");
                                        }

                                        echo("<input name="counttert" type="hidden" value="". $counttert."">");

                                    echo("</div>"); 

                                }
                                    echo("<div class="addTertDiv"></div>");

                            ?>
                        </div>
                    <?php                                                       
                        //Add New Subsection
                        //On button click create new textarea and increase "counttert"
                     echo ("<button type="button" id="addTertButton" value="".$counttert."">Click Me!</button>");
                     ?> 
                    </div>

任何帮助都将受到高度赞赏。

问题回答

You want the length property:

alert($( div.addTertDiv ).length);

Ok, 表面上称“Qu”具有规模功能。 <代码>length更为常见,但规模也应起作用。

此外,此行:

$( .addTertDiv ).append("<?php echo $tertDiv; ?>");

页: 1 TertDivs, 并附上你的答复结果。 这是你们想要的吗?

我认为你可能希望:

$( .tertiarywrapper ).append("<?php echo $tertDiv; ?>");




相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签