如何在html中显示一个php变量 [英] How to display a php variable into html

查看:126
本文介绍了如何在html中显示一个php变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



下面是我的php代码:

  var duration = <? echo $ postduration; ?取代; 

(上面的变量使用php来检索一个php变量)

谢谢

解决方案

让您的代码更加简洁, jQuery
$ b (1)在 < head>

 < script src =http://code.jquery。 COM / jquery的-latest.min.js>< /脚本> 

(2)创建一个要显示变量的元素,并给它一个ID,例如:

 < span id =printHere>< / span> 

(3)在您的JavaScript中添加它:

  var duration =<?php echo $ postduration?>; 
$('#printHere')。html(duration);

对于您的PHP,请尝试以下两个选项:

 <?= $ postduration?> 

或...

 <?php echo $ postduration; ?> 


I just want to know how can I display a javascript variable into html?

Below is my php code:

var duration = <? echo $postduration; ?>;

(The variable above uses php to retrieve a php variable)

Thank you

解决方案

Make your code more concise with jQuery:

(1) Add this in your <head>:

<script src="http://code.jquery.com/jquery-latest.min.js"></script>

(2) Create an element where you want the variable to be displayed, and give it an ID, e.g.:

<span id="printHere"></span>

(3) Add this in your JavaScript:

var duration="<?php echo $postduration ?>";
$('#printHere').html(duration);

For your PHP, try the following two options:

<?=$postduration?>

or...

<?php echo $postduration; ?>

这篇关于如何在html中显示一个php变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆