Syntax error: Illegal return statement in JavaScript

后端 未结 6 1494
南方客
南方客 2021-02-04 23:25

I am getting a really weird JavaScript error when I run this code:



        
6条回答
  •  栀梦
    栀梦 (楼主)
    2021-02-04 23:54

    return only makes sense inside a function. There is no function in your code.

    Also, your code is worthy if the Department of Redundancy Department. Assuming you move it to a proper function, this would be better:

    return confirm(".json_encode($message).");
    

    EDIT much much later: Changed code to use json_encode to ensure the message contents don't break just because of an apostrophe in the message.

提交回复
热议问题