JQuery添加<a> element to td with Cell Index Row Index

时间:2017-03-14 10:21:54

标签: jquery html

I have data from database that needs to be placed according to the cell index and row index as shown:

<script>
        $('.myTable tr:eq( <?php echo $row; ?> )').find('td:eq(<?php echo $col; ?>)').text('<?php echo $data; ?>');
</script>

But how do I add link to the td? I've tried this:

<script>
        $('.myTable tr:eq( <?php echo $row; ?> )').find('td:eq(<?php echo $col; ?>)').html('<?php echo "<a href='#' id='data'>" .$data. "</a>"; ?>');
</script>

and this:

<script>
        $('.myTable tr:eq( <?php echo $row; ?> )').find('td:eq(<?php echo $col; ?>)').append('<?php echo "<a href='#' id='data'>" .$data. "</a>"; ?>');
</script>

But none is working. Am I doing it wrong?

2 个答案:

答案 0 :(得分:0)

试试这个:

<script>
        $('.myTable tr:eq( <?php echo $row; ?> )').find('td:eq(<?php echo $col; ?>)').html('<?php echo "<a href=\'#\' id=\'data\'>" .$data. "</a>"; ?>');
</script>

答案 1 :(得分:0)

试试这个:

<script>
    var data = '<?php echo $data; ?>';
    $('.myTable tr:eq( <?php echo $row; ?> )').find('td:eq(<?php echo $col; ?>)').html("<a href='#' id='data'>"+ data +"</a>");
</script>