如何使用 jquery 隐藏帖子
我想知道如何使用 jquery 隐藏帖子。我能够使用 jquery api 中的代码来隐藏帖子
<head>
<style>
span { background:#def3ca; padding:3px; float:left; }
</style>
<script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
<button id="hidr">Hide</button>
<button id="showr">Show</button>
<div>
<span>Once</span> <span>upon</span> <span>a</span>
<span>time</span> <span>there</span> <span>were</span>
<span>three</span> <span>programmers...</span>
</div>
<script>
$("#hidr").click(function () {
$("span:last-child").hide("fast", function () {
// use callee so don't have to name the function
$(this).prev().hide("fast", arguments.callee);
});
});
$("#showr").click(function () {
$("span").show(2000);
});
</script>
</body>
,但问题是这不会保存隐藏,所以当我刷新浏览器时,帖子会再次显示。我希望能够让发布新闻后的用户隐藏,并为他隐藏该帖子,同时也为网站上的其他人隐藏。我不确定如何进行这项工作,所以我可以使用一些帮助。
I was wondering how I would be able to hide a post with jquery. I was able to get the posts to hide using this code from the jquery api
<head>
<style>
span { background:#def3ca; padding:3px; float:left; }
</style>
<script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
<button id="hidr">Hide</button>
<button id="showr">Show</button>
<div>
<span>Once</span> <span>upon</span> <span>a</span>
<span>time</span> <span>there</span> <span>were</span>
<span>three</span> <span>programmers...</span>
</div>
<script>
$("#hidr").click(function () {
$("span:last-child").hide("fast", function () {
// use callee so don't have to name the function
$(this).prev().hide("fast", arguments.callee);
});
});
$("#showr").click(function () {
$("span").show(2000);
});
</script>
</body>
but the problem is that this doesn't save the hide so when I refresh the browser the post is shown again. I want to be able to have the user who posted the post press hide and have the post hide for him but also hide for everyone else on the site. I'm not sure how to make this work though so I could use some help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果你想要的行为
>但也对站点上的其他人隐藏,
您必须将各部分的状态保留在数据库中。然后,您可以构建一个助手,根据该部分的 id 返回是否必须显示该部分...
If you want the behaviour
> but also hide for everyone else on the site
you will have to persist the state of the sections in a database. Then you can build a helper that returns you if a section has to be displayed or not based on the section's id...
也许给跨度某种ID。每次隐藏一个时,请使用 AJAX 请求来发布 ID 并将其保存到会话中。然后,当页面刷新时,您可以隐藏跨度服务器端或将 ID 写入隐藏字段并使用客户端脚本隐藏跨度。
Maybe give the spans some kind of ID. Every time you hide one, use an AJAX request to post the id and save it to session. Then when the page refreshes you can either hide the spans server side or write the IDs to a hidden field and use client script to hide the spans.