开发者

Does jQuery in table tag allowed?

开发者 https://www.devze.com 2023-04-13 08:34 出处:网络
I have this php-jquery-html pseudo-structure: <table> <?php while ($r = mysql_fetch_array($sth)){ ?>

I have this php-jquery-html pseudo-structure:

<table>
<?php while ($r = mysql_fetch_array($sth)){ ?>
    <tr>
        <td>
            Som开发者_运维技巧e HTML tag here
        </td>
    </tr>
    <script type="text/javascript">
        // Some jQuery here
    </script>
<?php } ?>
</table>

and I load this with AJAX in another page. I'm sure that $sth has 6 rows but it displays only 1 row. If I remove <script> section it works fine. Are we allowed to do this or I should check my syntax? (I didn't have any syntax error though!)


This is not valid HTML markup and could therefore cause issues with your layout.

script tags cannot be nested directly into table tags, however you can put this into your td tag

<table>
<?php while ($r = mysql_fetch_array($sth)){ ?>
    <tr>
        <td>
            Some HTML tag here            
            <script type="text/javascript">
                // Some jQuery here
            </script>
        </td>
    </tr>
<?php } ?>
</table>


Are we allowed to do this or

<script> elements are not allowed as child elements of a <table> or <tbody> element.

I should check my syntax?

Always check

I'm sure that $sth has 6 rows but it displays only 1 row.

Look at the HTML that is output by the PHP. Don't compare PHP to end rendering. Work out at what point in the chain the output differs from what you expect, and then compare that output to the stage immediately before it.

0

精彩评论

暂无评论...
验证码 换一张
取 消