JWorld@TW the best professional Java site in Taiwan
      註冊 | 登入 | 全文檢索 | 排行榜  

» JWorld@TW » Web Design 版  

按列印兼容模式列印這個話題 列印話題    把這個話題寄給朋友 寄給朋友    訂閱主題
reply to topicthreaded modego to previous topicgo to next topic
本主題所含的標籤
作者 如何分辨在網頁上按下的Enter鍵
chuchu0317





發文: 53
積分: 0
於 2011-10-25 18:24 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
請問如何分辨在網頁上按下的Enter鍵?

因為鍵盤上Enter鍵的KeyCode值都是13,
請問我可以如何辨別?
(利用JavaScript)

謝謝!


reply to postreply to post
作者 Re:如何分辨在網頁上按下的Enter鍵 [Re:chuchu0317]
kenshin520





發文: 109
積分: 0
於 2011-10-26 10:47 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
不太懂你的意思耶

你既然都知道Enter的KeyCode是13了,那請問你要跟什麼做分別?

你說在『網頁』裡,那所有你做的東西都在『網頁』裡不是嗎?Smile


reply to postreply to post
作者 Re:如何分辨在網頁上按下的Enter鍵 [Re:chuchu0317]
anda





發文: 95
積分: 0
於 2011-10-26 10:53 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
希望以下例題對你有幫助
<html>
<body>
<script type="text/javascript">
function noNumbersEnvelope
{
var keynum
var keychar
var numcheck

if(window.event) // IE
{
keynum = e.keyCode
}
else if(e.which) // Netscape/Firefox/Opera
{
keynum = e.which
}
keychar = String.fromCharCode(keynum)
numcheck = /\d/
return !numcheck.test(keychar)
}
</script>

<form>
<input type="text" onkeypress="return noNumbers(event)" />
</form>
</body>
</html>


reply to postreply to post
作者 Re:如何分辨在網頁上按下的Enter鍵 [Re:chuchu0317]
roytsang





發文: 620
積分: 1
於 2011-10-26 13:46 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
你是不是要這個東西呢?
我這段code detect 了user 有沒有在按enter 同時按Ctrl,Alt或Shit鍵:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<html>
<body>
<script type="text/javascript">
 
  function getEventObject(E)
  {
    return (window.event? event : E);
  }
  
  function readKey(e)
  {
    var keynum
    var keychar
    var numcheck
    evtObj=getEventObject(e);
    if ((evtObj.keyCode==13))
        {
          msg="Enter Key is pressed.";
      if (evtObj.shiftKey)
            msg+="<br>Shift Key is pressed.";
          if (evtObj.altKey)
            msg+="<br>Alt Key is pressed.";
          if (evtObj.ctrlKey)
            msg+="<br>Ctrl Key is pressed.";
          document.getElementById("error").innerHTML=msg;            
      }
    return false;
  }
</script>
<form onsubmit="return false">
<input type="text" onkeydown="return readKey(event)" />
</form>
<div id="error">
</div>
</body>
</html>


roytsang edited on 2011-10-26 14:43
reply to postreply to post
作者 Re:如何分辨在網頁上按下的Enter鍵 [Re:chuchu0317]
chuchu0317





發文: 53
積分: 0
於 2011-10-26 15:21 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
謝謝大家的解答...

我需要的是可以分辨一般 PC 那種鍵盤的兩個 Enter,
一個在中間, 一個在數字鍵盤那

因為兩個回傳回來的 Event.KeyCode 都是 13, 導致無法分辨,
今天爬文得知, Enter 鍵 虛擬碼 Return 的char code都是13,
須從 Scan Code 來做分辨, 請問有人知道 JavaScript 可以取得 Scan Code 嗎?

謝謝大家~~


reply to postreply to post
» JWorld@TW »  Web Design 版

reply to topicthreaded modego to previous topicgo to next topic
  已讀文章
  新的文章
  被刪除的文章
Jump to the top of page

JWorld@TW 本站商標資訊

Powered by Powerful JuteForum® Version Jute 1.5.8