我想让我的聊天弹出没有重新加载,我使用超链接传递user_id
这是我之前做的(页面加载)
链接格式:
<a target='_top' 'style='text-decoration:none;color:#fff;margin-left:20;' href='index.php?to=USER001'><b>";
这将重定向到我的索引$_GET['to'] = USER001(但页面重新加载)
我重新制作了它,这样页面就不会重新加载新链接格式
<a target='_top' 'style='text-decoration:none;color:#fff;margin-left:20;' href='#' rel ='index.php?to="USER001"'><b>";
它将我发送到localhost/index.php#我注意到如果我这样做它不会给我值所以我把它改成
<a target='_top' 'style='text-decoration:none;color:#fff;margin-left:20;' href='#USER001' rel ='index.php?to="USER001"'><b>";
我可以得到值USER001,如果这样的话,如何?有更好的方法吗?
我试图获得值USER001
不要使用#字符来禁用超链接你应该写
<a target='_top' 'style='text-decoration:none;color:#fff;margin-left:20;' href='javascript:;' rel ='index.php?to="USER001"'>
但是请注意,你需要在javascript, jquery或任何你正在使用的定义点击动作。
如果你用jQuery编写
$(a).click(function(){alert(0);});
,点击将提示0,但不会重定向到'/'文件夹。取消href应该是href="javascript:;"而不是像web上很多地方写的那样href="#"
- 添加id属性到超链接(让我们说
test_a
) - 添加属性
data-user-id="USER_001"
到超链接 -
在你的javascript中写:
$(document).ready(function(){ var user_id = $("#test_a").attr('data-user-id'); // will get you the value you need });
一旦你在javascript中有了它你就可以通过ajax将它传递给服务器或者你可以在当前页面中使用它而不刷新