传递在javascript函数中包含空格的URL
我试图在传递在javascript函数中包含空格的URL,javascript,php,jquery,Javascript,Php,Jquery,我试图在javascriptonclick函数中传递URL,但它在控制台日志上返回missing)错误,我对它进行了实验,发现URL包含特殊字符,有时还包含空格,可以逃避onclick事件 我从PHP脚本获取url $actual_link = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"; 并在onclick事件中传递它 <a href="#" class="btn btn-primary" id="main" onclick="g
javascript
onclick
函数中传递URL,但它在控制台日志上返回missing)
错误,我对它进行了实验,发现URL包含特殊字符,有时还包含空格,可以逃避onclick
事件
我从PHP
脚本获取url
$actual_link = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
并在onclick事件中传递它
<a href="#" class="btn btn-primary" id="main" onclick="getContent(<?php echo $actual_link;?>);">Content 1</a>
我的问题是如何在javascript函数中传递url文本。您需要在php输出周围加引号,以便将字符串传递给函数:
onclick="getContent('<?php echo $actual_link;?>');">
// ^^ ^^
onclick="getContent('<?php echo $actual_link;?>');">
onclick=“getContent(“”);”>
// ^^ ^^
您需要在php输出周围加引号,以便将字符串传递给函数:
onclick="getContent('<?php echo $actual_link;?>');">
// ^^ ^^
onclick=“getContent(“”);”>
// ^^ ^^
在getContent
函数中缺少一个'
onclick="getContent('<?php echo $actual_link;?>');">
onclick=“getContent(“”);”>
在getContent
函数中缺少一个'
onclick="getContent('<?php echo $actual_link;?>');">
onclick=“getContent(“”);”>