【问题标题】:How to call javascript function with php input value如何使用php输入值调用javascript函数
【发布时间】:2013-03-21 13:55:59
【问题描述】:

我想用这样的php参数调用一个javascript函数:

<script type="text/javascript">formatCurrency(<?php echo $item['price']; ?>);</script>

不幸的是,出了点问题,html 什么都不显示,有人可以建议我该怎么做吗?

【问题讨论】:

  • 查看 HTML 输出中的内容,即。页面来源。
  • firebug 没有显示错误,html 很干净,好像没有给出输出。并且 formatCurrency() 接受两个整数蚂蚁字符串
  • 您不会看到任何输出,因为&lt;script type= 不会输出任何内容。您需要在某处打印它。
  • @SilentCave like Voitcus 声明您必须在某处打印它。至少您可以将结果放在这样的 alert() 函数中:alert(formatCurrency(...))
  • 更短的语法:

标签: php javascript input


【解决方案1】:

看来我忘了添加 document.write(),感谢您的缩短,看起来不错。所以

<script>document.write(formatCurrency('<?=$item['price']?>'));</script>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-08-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-05
    • 1970-01-01
    相关资源
    最近更新 更多