【问题标题】:Print Javascript function in htm php page在 htm php 页面中打印 Javascript 函数
【发布时间】:2015-03-17 02:38:30
【问题描述】:

这是我的 javascript 代码:

<script>
    $(function() {
        $('#input').validateCreditCard(function(result) {
            $('.log').html('Card type: ' + (result.card_type == null ? '-' : result.card_type.name)
                     + '<br>Valid: ' + result.valid
                     + '<br>Length valid: ' + result.length_valid
                     + '<br>Luhn valid: ' + result.luhn_valid);
        });
    });
</script>

我在 html 标签中打印结果值,例如:

<h1><script>document.write(result.card_type.name())</script></h1>



<h1><script>document.write(result.valid())</script></h1>



<h1><script>document.write(result.length_valid())</script></h1>



<h1><script>document.write(result.luhn_valid())</script></h1>

bt 它没有显示价值..!!

【问题讨论】:

  • 不要使用document.write,而是使用jquery的.html().text()
  • 我想在 html 标签之间打印“result.length_valid”..!!
  • 然后在html标签之间连接起来..!!
  • bt 如何连接??
  • any1 知道如何在 html 标签中打印结果值??

标签: javascript php html


【解决方案1】:

“结果”变量是该函数的本地变量。你不能像那样在文档中使用它。

删除 HTML 中的这 4 行,然后添加:

<h1 class="log"></h1>

你得到想要的结果了吗?如果不是,您需要更好地解释什么是“validateCreditCard”。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-09-28
    • 1970-01-01
    • 2011-09-22
    • 2017-07-28
    • 1970-01-01
    • 1970-01-01
    • 2011-11-30
    • 1970-01-01
    相关资源
    最近更新 更多