【问题标题】:SyntaxError: identifier starts immediately after numeric literal, str_replace variable to javascriptSyntaxError:标识符在数字文字之后立即开始,str_replace变量到javascript
【发布时间】:2017-07-31 07:55:36
【问题描述】:

所以我有这个变量

$number = "1944/UN31/KEP/2017" 然后我想将"/" 替换为"" 所以我创建了新变量:

$number2 = str_replace("/","",$number) // the result would be : 1944UN31KEP2017

我可以在使用之前将我的 $number 变量访问到 js(在 laravel 刀片中):

onClick="doPrintTxtdaftar({{ $number}});">Print</a>

但是当我替换了字符串和第二个变量时:

onClick="doPrintTxtdaftar({{ $number2}});">Print</a>

我的调试器出现错误提示:SyntaxError: identifier 在数字文字之后立即开始

它指出了我的第二个变量值:1944UN31KEP2017

有人可以帮我吗...谢谢

【问题讨论】:

    标签: javascript php laravel laravel-blade


    【解决方案1】:

    用引号括起来

    改变这个:

    onClick="doPrintTxtdaftar( {{$number}} )">Print</a>
    

    到:

    onClick="doPrintTxtdaftar( '{{$number}}' )">Print</a>
    

    希望这对你有用!!!

    【讨论】:

    • @www.cahyonegoro.com 很高兴我的回答对你有用...干杯伙伴
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多