如何在php代码中编写jquery代码

时间:2013-12-10 09:44:42

标签: php mysql

您好,我想在MySQL查询与特定ID匹配时添加一些JQuery代码,这是我的代码:

<?php
$chkgreenmark ="select * from TABLE where PARAM = '$VARIABLE'";
$sqlchkgreenmark = mysqli_query($GLOBALS['mysqli'],$chkgreenmark);
$numsqlchkgreenmark = mysqli_num_rows($sqlchkgreenmark);
if($numsqlchkgreenmark > 0) { ?>

<script type="text/javascript">
    $(".calendercolumn .dragbox #dragID").append("<div class='detailssaved'><a href='#' ><img src='./images/check_mark.JPG' height='15' width='15'></a></div>");
</script>
<?php 
}?>

问题是,即使我没有任何结果,我也会得到JQuery代码。

任何人都可以帮助我吗?

3 个答案:

答案 0 :(得分:3)

试试这个

<?php
    $chkgreenmark ="select * from TABLE where PARAM = '$VARIABLE'";
    $sqlchkgreenmark = mysqli_query($GLOBALS['mysqli'],$chkgreenmark);
    $numsqlchkgreenmark = mysqli_num_rows($sqlchkgreenmark);
    if($numsqlchkgreenmark > 0)
    {
          echo '<script type="text/javascript">
            $(".calendercolumn .dragbox #dragID").append("<div class=\'detailssaved\'><a href=\'#\' ><img src=\'./images/check_mark.JPG\' height=\'15\' width=\'15\'></a></div>");
          </script>';
    }
?>

Live Demo

答案 1 :(得分:0)

我尝试了@rynhe的答案,但在我添加文档就绪功能

之前,我没有为我工作
<?php
    $chkgreenmark ="select * from TABLE where PARAM = '$VARIABLE'";
    $sqlchkgreenmark = mysqli_query($GLOBALS['mysqli'],$chkgreenmark);
    $numsqlchkgreenmark = mysqli_num_rows($sqlchkgreenmark);
    if($numsqlchkgreenmark > 0)
    {
          echo '<script type="text/javascript">
                $(document).ready(function(e) {
                     $(".calendercolumn .dragbox #dragID").append("<div class=\'detailssaved\'><a href=\'#\' ><img src=\'./images/check_mark.JPG\' height=\'15\' width=\'15\'></a></div>");
                });
          </script>';
    }
?>

答案 2 :(得分:-1)

在你可以使用php标签的php文件或页面上,你可以将php写入jquery脚本。所以你可以像下面一样使用它;

<script type="text/javascript">
    $(".calendercolumn .dragbox <?php echo $id;?>").append("<div class='detailssaved'><a href='#' ><img src='./images/check_mark.JPG' height='15' width='15'></a></div>");
</script>