-1
我想做一個谷歌瀏覽器擴展,其中有一個簡單的index.html。在該頁面上,當我按alt + ctrl + a然後鼠標焦點應該在第一個文本框上。在Chrome擴展中的特定按鍵事件
我很困難如何實現鍵盤快捷鍵的代碼。
我想做一個谷歌瀏覽器擴展,其中有一個簡單的index.html。在該頁面上,當我按alt + ctrl + a然後鼠標焦點應該在第一個文本框上。在Chrome擴展中的特定按鍵事件
我很困難如何實現鍵盤快捷鍵的代碼。
你可能要考慮的accesskey
語法:
http://www.cs.tut.fi/~jkorpela/forms/accesskey.html#ex
HTH :)
編輯:對,例如網頁是不是真的那麼好那麼這裏有一個參考實現。
基本上,你想要做的是爲C-A-f添加accesskey="f"
以引起對輸入字段的注意。
略從Wikipedia的基本搜索表單變形例:
<form action="http://en.wikipedia.org/w/index.php" id="searchform">
<div id="simpleSearch">
<input type="text" name="search" value="Example text" title="Search Wikipedia [f]" accesskey="f" id="searchInput" />
<button type="submit" name="button" title="Search Wikipedia for this text" id="searchButton"><img src="foo.png" alt="Search" title="Search" /></button>
<input type='hidden' name="title" value="Special:Search"/>
</div>
</form>
在這個例子中,推C-A-F應使瀏覽器聚焦到期望的框。
當你在它的時候,你可能想要一個JavaScript甚至綁定到表單,這樣如果用戶使用鼠標來放置該字段,它仍然會自動選擇所有文本以便於輸入。
首先,把這個在你的頭(或js文件):
function SelectAll(id)
{
document.getElementById(id).focus();
document.getElementById(id).select();
}
...然後添加一個onClick事件的輸入字段looke這樣的:onClick="SelectAll('searchInput');"
,造成這一行:
<input type="text" name="search" value="Example text" title="Search Wikipedia [f]" accesskey="f" id="searchInput" onClick="SelectAll('searchInput');" />