[英]Trying to make a dynamic PHP link go to another page using Javascript onClick
I have a drop down menu that populates dynamically using a php function. 我有一个下拉菜单,可使用php函数动态填充。 the return string is as follows:
返回字符串如下:
$return_string .= "<li class='dropdown-item-row row' style='" . $style . "' onClick='window.location.href='" . $row['link'] . "'>
<span class='dd-pic'>
<img src='" . $user_data['profile_pic'] . "'>
</span>
<span class='dd-right'>
<span class='dd-date'>
" . $time_message . "
</span>
<span class='dd-notif-text'>" . $row['message'] . "</span>
</span>
</li>";
When the user clicks on the link it will take them to the specific notification. 当用户单击链接时,它将带他们到特定的通知。 I have on the
<li>
tag onClick='window.location.href='" . $row['link'] . "'
The error I'm getting here is Uncaught SyntaxError: Unexpected end of input. 我在
<li>
标记上onClick='window.location.href='" . $row['link'] . "'
我在这里遇到的错误是Uncaught SyntaxError:输入意外结束。 Can anyone see something that I'm missing here? 有人可以看到我在这里想念的东西吗?
It works locally if I wrap it in an <a>
tag, but this is silly given it's around an <li>
tag and will likely not work on remote server. 如果我将其包装在
<a>
标记中,它将在本地运行,但是考虑到它在<li>
标记周围,这是很愚蠢的,并且可能无法在远程服务器上运行。 I thought something simple in JS like this might be the solution. 我认为JS这样简单的方法可能是解决方案。
Any help appreciated! 任何帮助表示赞赏! Thanks is advance.
感谢是前进。
Inside double quotes "$var" simple variables don't need to be concatenated. 在双引号中,“ $ var”简单变量不需要连接。 This should work:
这应该工作:
$return_string .= "<li class='dropdown-item-row row'
style='$style'
onClick=\"javascript:window.location.href='" . $row['link'] . "';\">
<span class='dd-pic'>
<img src='" . $user_data['profile_pic'] . "'>
</span>
<span class='dd-right'>
<span class='dd-date'>$time_message</span>
<span class='dd-notif-text'>" . $row['message'] . "</span>
</span>
</li>";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.