简体   繁体   English

语法错误:预期的表达式,得到 ''

[英]SyntaxError: expected expression, got ''

I know there are many questions with this same title, but all I've seen do not apply to my problem.我知道有很多相同标题的问题,但我所看到的都不适用于我的问题。

I currently have a PHP function that looks like this:我目前有一个 PHP 函数,如下所示:

function mostraFraseStatus($i, $f){
        print'document.getElementById("cliente'.$i.'").innerHTML = "<span style=\'color:#FF0000\'>'.$f.'</span>";';
    }

Within the validations, it is executed this way:在验证中,它是这样执行的:

} else {
                        mostraFraseStatus($idProdutoSelecionado, "Text Here");
                    }

It works normally, but I need to change that print to an alert .它正常工作,但我需要将该print更改为alert I have tried the following:我尝试了以下方法:

function mostraFraseStatus($i, $f){
        echo "<script type='text/javascript'>alert('Test');</script>";
    }

However I am getting the title error while executing the function by the navigator: SyntaxError: expected expression, got '<'但是,我在通过导航器执行函数时收到标题错误: SyntaxError: expected expression, got '<'

How can I fix it?我该如何解决?

The error is most likely caused by echo 'ing a <script> block inside an existing <script> block.该错误很可能是由在现有<script>块中对<script>块进行echo引起的。 Simply change your code like so:只需像这样更改您的代码:

function mostraFraseStatus($i, $f){
    echo "alert('Test');";
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM