TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Show HN: How HN's upvote link works

11 点作者 asto将近 13 年前
<i>Each link has an anchor tag like this:</i><p><pre><code> &#60;a href="vote?for=4156127&#38;amp;dir=up&#38;amp;by=asto&#38;amp;auth=12345&#38;amp;whence=%6e%65%77%73" onclick="return vote(this)" id="up_4156127"&#62; &#60;img vspace="3" hspace="2" border="0" src="http://ycombinator.com/images/grayarrow.gif"&#62; &#60;/a&#62; </code></pre> <i>The vote function looks like this:</i><p><pre><code> function vote(node) { var v = node.id.split(/_/); // {'up', '123'} var item = v[1]; // hide arrows byId('up_' + item).style.visibility = 'hidden'; byId('down_' + item).style.visibility = 'hidden'; // ping server var ping = new Image(); ping.src = node.href; return false; // cancel browser nav </code></pre> <i>byId is getElementById. I don't know about you guys but I thought this was pretty neat!</i>

2 条评论

jgrahamc将近 13 年前
Which part did you find neat?
评论 #4156927 未加载
Xymak1y将近 13 年前
It's an interesting way to not use XMLHttpRequest for Ajax.
评论 #4157279 未加载