继承我在php中的当前代码,其中一个参数可以正常工作
<?php
$sid = "012";
echo '<input type="button" value="Submit" onclick="changeConfirmed('.$sid.')">';
?>
现在我试图传递两个或更多参数,但似乎无法让它工作,这是我的尝试:
<?php
$name="abc
$sid = "012";
echo '<input type="button" value="Submit" onclick="changeConfirmed('.$sid.','.$name.')">';
?>
答案 0 :(得分:3)
您需要围绕参数引用或javascript将它们视为变量而不是字符串。
echo '<input type="button" value="Submit" onclick="changeConfirmed(\''.$sid.'\',\''.$name.'\')">';
答案 1 :(得分:2)
如果您的某个JavaScript函数参数是字符串,则必须将其正确地用引号括起来:
<?php
$name="abc";
$sid = "012";
echo '<input type="button" value="Submit" onclick="changeConfirmed('.$sid.',\''.$name.'\')">';
?>
你没有用引号括起来的$ sid,因为它看起来像一个数字。