dssjxvbv918586 2016-02-11 17:27
浏览 28
已采纳

将PHP值作为参数传递给jQuery并在alert [duplicate]中显示该值

This question already has an answer here:

Hello i want to display the value in alert . I passed the php value as a parameter in jquery and when i display that value in alert it shows empty Code is here

<button type="button" onclick="topSharedPosts('<?php echo $postID; ?>')" class="btn btn-success" value="<?php echo $postID; ?>"> Facebook </button>

Jquery Function

function topSharedPosts(id) {
       alert(id);
}
</div>
  • 写回答

1条回答 默认 最新

  • dqm83011 2016-02-11 17:35
    关注

    It's working for me:-

    1. your file must have .php extension not .html.

    Check the below code:-

    Alert.php:-

    <?php 
    $postID = 2;
    ?>
    <button type="button" onclick="topSharedPosts('<?php echo $postID; ?>')" class="btn btn-success" value="<?php echo $postID; ?>"> Facebook </button>
    
    <script type = "text/javascript">
    function topSharedPosts(id) {
           alert(id);
    }
    </script>
    

    Note:- there is no jquery in your code and my code. It's pure javascript. I have taken $postId value to check that code works or not, and it works fine.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法