Skip to content

Commit

Permalink
~添加键盘监听事件
Browse files Browse the repository at this point in the history
  • Loading branch information
binlyzhuo committed Mar 12, 2015
1 parent 3ccf455 commit f2c0a00
Showing 1 changed file with 30 additions and 2 deletions.
32 changes: 30 additions & 2 deletions src/Joke.Web/Views/Joke/Detail.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,34 @@
$(function () {
jokesfollow();
//
$(document).keydown(function (event) {
//alert(event.keyCode);
switch(event.keyCode)
{
case 37:
var link = $("#lastJokeLink").attr("href");
if ($.trim(link) != "") {
window.location.href = link;
}
else
{
alert('已结束');
}
break;
case 39:
var link = $("#nextJokeLink").attr("href");
if ($.trim(link) != "") {
window.location.href = link;
}
else {
alert('已结束');
}
break;
}
});
});
function jokesfollow() {
Expand Down Expand Up @@ -120,15 +148,15 @@
@if (nextJoke != null)
{
<em>下一篇:</em>
<a href="@JokeHelper.GetJokeDetail(nextJoke.ID)" title="@nextJoke.Title">@nextJoke.Title</a>
<a id="nextJokeLink" href="@JokeHelper.GetJokeDetail(nextJoke.ID)" title="@nextJoke.Title">@nextJoke.Title</a>
}

</span>
<span class="prev">
@if (lastJoke != null)
{
<em>上一篇:</em>
<a href="@JokeHelper.GetJokeDetail(lastJoke.ID)" title="@lastJoke.Title">@lastJoke.Title</a>
<a id="lastJokeLink" href="@JokeHelper.GetJokeDetail(lastJoke.ID)" title="@lastJoke.Title">@lastJoke.Title</a>
}

</span>
Expand Down

0 comments on commit f2c0a00

Please sign in to comment.