open the JQuery dialog by the div idAsk Question

问题:

I want to open a dialog for each product I have in my database.

But how can I open a dialog for all these div ID's I've in my database without hard coding it?

It looks like this: Website How can I get these information in the correct dialog

Dialog that needs to open:

                            <?php foreach($hotels as $key => $hotel)    {
                            ?>
                                <div class="click_div" id="<?php echo  
                                   $hotel['MaasduinId'];?>">
                                <?php echo $hotel['MaasduinNaam']; ?>
               </h3>

                                </div>

            <?php   } ?>

JQuery / PHP

                            foreach($hotels as $key => $hotel)
                {
                    ?>
                    <?php if ($hotel['MaasduinCategory'] == 'Appartementen'): ?>

                            <div class="products-<?php echo $hotel['MaasduinId'];?>">
                                <div class="maasduin-foto"><img style="width: 136px; height: 134px;" src="\Maasduinen-NW\image\<?php echo $hotel['MaasduinImage']; ?>">
                                    <?php if ($hotel['MaasduinPas'] == '1'): ?>
                                        <div class="maasduin-actiefoto">
                                            <img style="width: 40px; height: 40px;" src="\Maasduinen-NW\image\<?php echo $hotel['MaasduinPasfoto']; ?>">
                                        </div>
                                    <?php endif ?>
                                </div>
                                <div class="maasduin-naam"><?php echo $hotel['MaasduinNaam']; ?></h3></div>
                                <div class="maasduin-locatie"><?php echo $hotel['MaasduinLocatie']; ?></div>
                                <div class="maasduin-email"><?php echo $hotel['MaasduinEmail']; ?></div>
                                <div class="maasduin-telefoon"><?php echo $hotel['MaasduinTelefoon']; ?></div>
                                <div class="maasduin-website"><?php echo $hotel['MaasduinWebsite']; ?></div>
                <script>


                  var $dialog; 
                        $(document).ready(function () {

                            $(".click_div").on("click",function(e){
                              // $(this).attr('id') will return the id
                              $dialog = $(this).attr('id');
                              $dialog.showDialog();
                            });

                            $("div[class^='products-']").click(function () {
                                $dialog.dialog('open');
                                return false; ////cancel eventbubbeling
                            });
                        });

                        function showDialog() {
                            $dialog.dialog('open');
                            return false //cancel eventbubbeling
                        }

                </script>           

I hope someone can help me solve this problem.

标签: jquery
© 2014 TuiCode, Inc.