欢迎访问 夜阑小雨 我的学习碎片档案,这里记录了我的学习内容和工作中经验,希望给您带去帮助。

如何给wordpress添加Ctrl+Enter回复快捷键

javascript 夜阑小雨 5911℃ 0评论

如何给wordpress添加Ctrl+Enter回复快捷键?

我觉得这个不是必要的,但是对于一些经常聊QQ的人来说可能会更方便些,所以随大众,也给加上了。

但是找了几个添加的方法,总是有问题,后来才发现,关键点在于要button指定一个id=submit否则的话,js是捕捉不到id的。

具体的在comment.php里添加代码:

内容如下:

方法一:

1.首先是在模版的comments.php 底部加一段JS代码

<script type=”text/javascript”>

document.getElementById(“comment”).onkeydown = function (moz_ev)

{

var ev = null;

if (window.event){

ev = window.event;

}else{

ev = moz_ev;

}

if (ev != null && ev.ctrlKey && ev.keyCode == 13)

{

document.getElementById(“submit”).click();

}

}

</script>

。最后是找到这段,并修改:

<input name=”提交” type=”submit” id=”submit” tabindex=”5″ value=”提交Ctrl+Enter” />

方法二:

在 comments.php 中找到以下代码:

<TEXTAREA id=comment tabIndex=4 rows=10 cols=105 jQuery1250561977609="48"></TEXTAREA>

修改为:

<TEXTAREA id=comment onkeydown="if(event.ctrlKey&&event.keyCode==13){document.getElementById('submit').click();return false};" tabIndex=4 rows=10 cols=105></TEXTAREA>

总结:相比来说,第二种方法更简单,却实现了相同的效果。

需要注意的是:这里的id一定要和js里的id值一样不然无法处理。

转载请注明:夜阑小雨 » 如何给wordpress添加Ctrl+Enter回复快捷键

喜欢 (0)or分享 (0)
发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
(5)个小伙伴在吐槽
  1. 学习了,回去试试
    itkid2012-08-14 03:55 回复
  2. hello.
    thomas2010-09-06 09:20 回复
  3. Just want to say what a great blog you got here! I've been around for quite a lot of time, but finally decided to show my appreciation of your work! Thumbs up, and keep it going! Cheers Christian,Earn Free Vouchers / Cash
    Paichnafcof2010-06-08 20:56 回复
  4. Just want to say what a great blog you got here! I've been around for quite a lot of time, but finally decided to show my appreciation of your work! Thumbs up, and keep it going! Cheers Christian,Diet Guide!
    Paichnafcof2010-05-31 23:59 回复
  5. Just want to say what a great blog you got here! I've been around for quite a lot of time, but finally decided to show my appreciation of your work! Thumbs up, and keep it going! Cheers Christian, iwspo.net
    Paichnafcof2010-05-25 21:46 回复