[英]Uncaught Syntax error on onClick function javascript
I need to output some strings in the onclick anchor function.I have used proper escaping but anyhow its returning error. 我需要在onclick锚函数中输出一些字符串。我已经使用了正确的转义,但是无论如何它都会返回错误。
My code is: 我的代码是:
$output .= '<a title="Minus this" href="#" onclick = removefromCart("' . $item . '", "' . $nonce . '", ' . $deductQty . ');></a>';
And also used this : 并且还使用了这个:
$output .= '<a title="Minus this" href="#" onclick = "removefromCart("' . $item . '", "' . $nonce . '", ' . $deductQty . ')"></a>';
But in both cases there is Uncaught SyntaxError: Unexpected token } 但在两种情况下,都存在Uncaught SyntaxError:意外的令牌}
您应该使用单引号来表示HTML元素中的字符串
$output .= '<a title="Minus this" href="#" onclick = "removefromCart(\'' . $item . '\', \'' . $nonce . '\', ' . $deductQty . ')"></a>';
The quotes is totally wrong. 引号是完全错误的。 Do this way, using the first one:
使用第一个方法执行以下操作:
$output .= '<a title="Minus this" href="#" onclick=\'removefromCart("' . $item . '", "' . $nonce . '", ' . $deductQty . ');\'></a>';
See the '
s I have added and removed spaces? 见
'
的I已添加和删除的空间? And please, next time, don't mingle both PHP and JavaScript. 而且,下次,请不要混用PHP和JavaScript。 It's confusingly dangerous.
这是令人困惑的危险。
See also: 也可以看看:
For greater than or equal to PHP5 大于或等于PHP5
$output .= '<a title="Minus this" href="#" onclick = removefromCart($item,$nonce,$deductQty);></a>';
For Less than PHP5 try it 对于不到PHP5的试用版
$output .= '<a title="Minus this" href="#" onclick = removefromCart(' . $item . ',' . $nonce . ', ' . $deductQty . ');></a>';
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.