Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/228.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从php调用javascript函数时出现问题_Javascript_Php_Jquery_Html - Fatal编程技术网

从php调用javascript函数时出现问题

从php调用javascript函数时出现问题,javascript,php,jquery,html,Javascript,Php,Jquery,Html,我正在努力做到以下几点: <html> <script type="text/javascript" src="jquery.js"></script> <a id="random">before</a> <script> function test(a) { document.getElementById('random').innerHTML="after with variable passed

我正在努力做到以下几点:

<html>
<script type="text/javascript" src="jquery.js"></script>

<a id="random">before</a>   
<script>
function test(a)
  {
      document.getElementById('random').innerHTML="after with variable passed in";
  }
function test2()
  {
      document.getElementById('random').innerHTML="after without variable passed in";
  }
</script>
<?php $sample = "hi"; ?>

<button onClick="test(<?php echo $sample;?>)">withVariable</button>

<button onClick="test2()">withoutVariable</button>
</html>

之前
功能测试(a)
{
document.getElementById('random').innerHTML=“after,传入变量”;
}
函数test2()
{
document.getElementById('random').innerHTML=“after,无需传入变量”;
}

由于
$sample
是一个字符串文本,因此需要用
'


因为
$sample
是一个字符串文本,所以需要用
'


因为
$sample
是一个字符串文本,所以需要用
'


因为
$sample
是一个字符串文本,所以需要用
'


如果要传递字符串变量,则需要在值周围添加引号,如下所示:

<button onClick="test('<?php echo $sample;?>')">withVariable</button>

如果要传递字符串变量,则需要在值周围添加引号,如下所示:

<button onClick="test('<?php echo $sample;?>')">withVariable</button>

如果要传递字符串变量,则需要在值周围添加引号,如下所示:

<button onClick="test('<?php echo $sample;?>')">withVariable</button>

如果要传递字符串变量,则需要在值周围添加引号,如下所示:

<button onClick="test('<?php echo $sample;?>')">withVariable</button>

哇,我要是早点问就好了。。这么小的错误哇,我真希望早点问。。这么小的错误哇,我真希望早点问。。这么小的错误哇,我真希望早点问。。这么小的错误