当我通过
调用脚本时<script type="text/javascript"
src="include/javascript/test_something.js?v=1128557"></script>
如何引用 html 中传递的变量 V?
提前致谢!
最佳答案
最简单的方法是使用服务器端技术。这是在 php 中。
<?php
$v=1128557;
?>
<script type="text/javascript">
//This will make this value available to javascript too
var val=<?php=$v?>;
</script>
<script type="text/javascript"
src="include/javascript/test_something.js?v=<?php=$v?>"></script>
...
...
...
<div id='baba<?php=$v?>'>
...
...
</div>
这将被翻译为以下 html
<script type="text/javascript">
//This will make this value available to javascript too
var val=1128557;
</script>
<script type="text/javascript"
src="include/javascript/test_something.js?v=1128557"></script>
...
...
...
<div id='baba1128557'>
...
...
</div>
关于javascript - 如何在html中引用传递给javascript的参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8829438/