繁体   English   中英

有什么方法可以使用jQuery或JavaScript打开我的网站上的链接(或导航到其他页面)?

[英]Is there any way I can open a link on my site (or navigate to a different page in general) using jQuery or JavaScript?

我一直在到处寻找有关某种信息的信息,如果可以的话,怎么办?

本来我应该为电子商务任务制作PowerPoint,而是因为我更喜欢编写HTML而不是与PowerPoint一起工作而要求制作网页。 我正在和我旁边的人聊天,最终他打赌我无法让我的网站像PowerPoint一样外观和工作,所以我选择了他。 那么,有什么方法可以通过按右箭头来翻一页的呢? 任何帮助表示赞赏!

使用Impress js: http//bartaz.github.io/impress.js/

它是一个用于PowerPoint幻灯片演示的jQuery插件(并提供更多功能)

有很多使网站看起来像PowerPoint应用程序的可能性。 使用jQuery(这是我最喜欢的JavaScript库),可以轻松识别按键。

$(document).keypress(function(e) {
if(e.which == 39){
    //Right arrow key, now trigger an event or a function. Could be for example: loading new data into a div with ajax or sliding your content so that the next screen is shown.        
}
});

请参阅此页面以标识字符代码: http : //www.cambiaresearch.com/articles/15/javascript-char-codes-key-codes

jQuery还提供了animate方法( https://api.jquery.com/animate/ ),该方法可用于制作平滑的动画,幻灯片,而不能制作平滑的动画。 借助HTML,CSS和jQuery的知识,您可以轻松地制作类似于PowerPoint的应用程序。

干杯。

使用标准javascript(IE无需下载库),这相当简单。

假设每个页面都有自己的URL,您应该能够在主体上添加一个“ onkeypress”事件,该事件根据使用event.keyCode按下的特定键来执行操作。

例如

<script>
function navigate( event ) {
  if ( event.keyCode == 39 ) {
    // right arrow pressed
    window.location.href = "the url of your next page";
  }

  if ( event.keyCode == 37 ) {
    // left arrow pressed
    window.location.href = "the url of your previous page";
  }
}

</script>
<body onkeypress="navigate( event )">
...

有更多优雅的解决方案,但这应该可以帮助您入门。

一旦有了基本的工作原理,您就可以使用console.log( event.keyCode );找出键码是什么console.log( event.keyCode ); ,或在线查找它们(那里有很多参考网站)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM