表格不正常?

时间:2016-10-27 17:16:01

标签: php jquery html

我正在努力建立一个提供php的网站。我有一个函数,我在for循环中使用,数据库的结果在函数中传递。代码是这样的:

<?php 
function table_values($row0,$row1,$row2,$row3,$row4,$row5){

    $table_element = "<div id=\"$row0\" class='tab'>
                                    <div class='tab-header'>";
        switch ($row1) {
            case "Tiscali":
                $img = "<img src='images/tiscali.png' alt='Tiscali' />";
                break;
            case "Infostrada":
                $img = "<img src='images/infostrada.png' alt='Infostrada' />";
                break;
            case "Fastweb":
                $img = "<img src='images/fastweb.png' alt='Fastweb' />";
                break;
            case "TIM":
                $img = "<img src='images/telecom-italia.png' alt='TIM' />";
                break;
        }
        $table_element = "".
            $table_element . " $img <span>$row2</span></div>
                                <div class='block'>
                                    <div class='first-set-block'>
                                        <span class='s2'>Download</span><br /><span class='s3'>$row3 Mbps</span>
                                    </div>
                                    <div class='first-set-block'>
                                        <span class='s4'>ATTIVAZIONE</span><br /><span class='s5'>GRATUITA</span>
                                    </div>
                                </div>
                                <div class='block'>
                                    <div class='block-header'>
                                        Costo standard
                                    </div>
                                    <div class='block-describe-standard'>
                                        <span class='s6'>&#8364; $row4</span>
                                    </div>
                                </div>
                                <div class='block'>
                                    <div class='block-header'>
                                        Promozione
                                    </div>
                                    <div class='block-describe-promozione'>
                                        <span class='s7'>&#8364; $row5</span>
                                    </div>
                                </div>
                                <div class='block'>
                                    <div class='block-header-last'>
                                        Costo 1 anno
                                    </div>
                                    <div class='block-describe-costo'>
                                        <span class='desc1'>&#8364; 21</span>
                                        <span class='desc2'>.32<br />&#8364;/mese</span>
                                        <button class='ordina-offerta'>Ordina</button>
                                    </div>

                                </div>
                               </div>
                               <div class='black'>
                                    </div>
                               <div class='popup' id='pop".$row0."'>
                               <form method='post' action='off.php'>
                                    <span class='close'>&times;</span>


                                    <table width='100%' style='text-align: center;'>
                                        <tr>
                                            <td>Nome: </td><td><input type='text' name='nome' /></td>
                                        </tr>
                                        <tr>
                                            <td>Cognome: </td><td><input type='text' name='cognome' /></td>
                                        </tr>
                                         <tr>
                                            <td>id: </td><td><input type='text' name='id' value=\"$row0\" /></td>
                                        </tr>
                                        <tr>
                                            <td colspan='2'><input type='submit' value='Carica' class='carica' /></td>
                                        </tr>
                                    </table> 
                                </form>
                                </div>";

                return $table_element;
            }
?>

但出于一个原因,我希望div black和div popup成为div类选项卡的子项,但是当我将上面的代码更改为此时,提交按钮不起作用。

<?php 
function table_values($row0,$row1,$row2,$row3,$row4,$row5){

    $table_element = "<div id=\"$row0\" class='tab'>
                                    <div class='tab-header'>";
        switch ($row1) {
            case "Tiscali":
                $img = "<img src='images/tiscali.png' alt='Tiscali' />";
                break;
            case "Infostrada":
                $img = "<img src='images/infostrada.png' alt='Infostrada' />";
                break;
            case "Fastweb":
                $img = "<img src='images/fastweb.png' alt='Fastweb' />";
                break;
            case "TIM":
                $img = "<img src='images/telecom-italia.png' alt='TIM' />";
                break;
        }
            $table_element = "".
                $table_element . " $img <span>$row2</span></div>
                            <div class='block'>
                                <div class='first-set-block'>
                                    <span class='s2'>Download</span><br /><span class='s3'>$row3 Mbps</span>
                                </div>
                                <div class='first-set-block'>
                                    <span class='s4'>ATTIVAZIONE</span><br /><span class='s5'>GRATUITA</span>
                                </div>
                            </div>
                            <div class='block'>
                                <div class='block-header'>
                                    Costo standard
                                </div>
                                <div class='block-describe-standard'>
                                    <span class='s6'>&#8364; $row4</span>
                                </div>
                            </div>
                            <div class='block'>
                                <div class='block-header'>
                                    Promozione
                                </div>
                                <div class='block-describe-promozione'>
                                    <span class='s7'>&#8364; $row5</span>
                                </div>
                            </div>
                            <div class='block'>
                                <div class='block-header-last'>
                                    Costo 1 anno
                                </div>
                                <div class='block-describe-costo'>
                                    <span class='desc1'>&#8364; 21</span>
                                    <span class='desc2'>.32<br />&#8364;/mese</span>
                                    <button class='ordina-offerta'>Ordina</button>
                                </div>

                            </div>

                           <div class='black'>
                                </div>
                           <div class='popup' id='pop".$row0."'>
                           <form method='post' action='off.php'>
                                <span class='close'>&times;</span>


                                <table width='100%' style='text-align: center;'>
                                    <tr>
                                        <td>Nome: </td><td><input type='text' name='nome' /></td>
                                    </tr>
                                    <tr>
                                        <td>Cognome: </td><td><input type='text' name='cognome' /></td>
                                    </tr>
                                     <tr>
                                        <td>id: </td><td><input type='text' name='id' value=\"$row0\" /></td>
                                    </tr>
                                    <tr>
                                        <td colspan='2'><input type='submit' value='Carica' class='carica' /></td>
                                    </tr>
                                </table> 
                            </form>
                            </div></div>";

                return $table_element;
            }
?>

有人知道为什么吗?由于jquery的原因,我需要让它们成为tab类的子项,以便使用parent()函数。提前感谢,希望我很清楚。

2 个答案:

答案 0 :(得分:0)

从头开始动态创建的表单(使用JS)将无法正确处理,因为它在加载后插入页面,因为它在代码上方显示。相反,您可以使用HTML代码创建表单,之后您可以根据来自服务器的数据(PHP代码)使用JS更改元素。
希望这会有所帮助。

答案 1 :(得分:0)

这是主要页面中包含的Jquery部分..


    
    $(document).ready(function(){
            $('.tab').click(function(){
            var id=$(this).attr('id');
                $('#black' + id).fadeIn();
                $('#pop' + id).fadeIn();
                return false;
            });
            $('.close').click(function(){
            var id=$(this).parent().parent().parent().attr('id');
                $('#black' + id).fadeOut();
                $('#pop' + id).fadeOut();
                $( '.grazie-popup' ).fadeOut();
                return false;
            });
            $('.black').click(function(){
            var id=$(this).parent().attr('id');
                $('#black' + id).fadeOut();
                $('#pop' + id).fadeOut();
                $( '.grazie-popup' ).fadeOut();
                return false;
            });
            if ( $( '.grazie-popup' ).length ) {
                $('#black').delay( 400 ).fadeIn();
                $( '.grazie-popup' ).delay( 600 ).fadeIn();
            }
        });


问题就像我之前解释的那样,当我想要制作&lt; div class =“black”&gt;和&lt; div class =“popup”&gt;儿童的&lt; div class =“tab”&gt;提交按钮不起作用。