Home  >  Article  >  Backend Development  >  html中php值传递到JS解决方案

html中php值传递到JS解决方案

WBOY
WBOYOriginal
2016-06-13 13:34:25796browse

html中php值传递到JS
 
还是没怎么看懂各位的另开一贴详细诉说我的请求··
红色的数字我希望用html中嵌套的一个php的值$time传递到JS中,
在html调用JS显示倒计时时间(已实现),当时间结束时,触动表单提交按钮。
问题在于怎么把那个php的$time值传递到js中,因为倒计时时间因为试卷类型不同时间就不同


------解决方案--------------------
//是这个意思吗?

HTML code
<span id="time"><?php echo $time; ?></span>
<script type="text/javascript">
var maxtime = parseInt(document.getElementById('time').innerHTML) * 60;
</script>
<br><font color="#e78608">------解决方案--------------------</font><br>你这个是 js 文件,在 html 中是通过<br><script src="filename.js"></script><br>加载的,这没有问题吧?<br>如果是直接写在 html 文件中,那么这个 html 文件就必须是 php 后缀<br><br>同样的道理,要想 filename.js 中的 php 代码被执行,就需要修改 js 后缀为 php<br>filename.php<br><br>加载时写作<br><script src="filename.php"></script><br>
<br><font color="#e78608">------解决方案--------------------</font><br><script> var maxtime = parseInt(document.getElementById('time').innerHTML)*60;</script> 放在span标签后面。
<br><font color="#e78608">------解决方案--------------------</font><br>var maxtime = =$time?>*60;<br>  <br>
<br><font color="#e78608">------解决方案--------------------</font><br>
HTML code


------解决方案--------------------
HTML
document.表单名.submit();

DHTML
document.getElementById('表单id').submit():.
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn