[jQuery] 組合鍵 我飛in 飛out
user 有需求,要有一個隱藏欄位,需要時而且有權限的user才能顯示讓user輸入,剛好最近小弟在研究jQuery,所以用組合鍵控管顯示(ALT+,)跟隱藏(ALT+.),在這邊記錄一下
1: <HTML>
2: <HEAD>
3: <script type="Text/JavaScript" src="jquery.js"></script>
1:
2: <script type="Text/JavaScript">
3: var isAlt = false;
4: $(document).keydown(function (e) {
5: if (e.keyCode == 18) {
6: isAlt = true;
7: }
//因特殊需求,所以組點鍵有點機車 【ALT+,】=飛IN 【 ALT+.】=飛OUT
8: if (e.keyCode == 188 && isAlt) {
9: $("#txt_Fade").fadeIn("slow", function () {
10: $(this).val("我飛IN了");
11: })
12: }
13: if (e.keyCode == 190 && isAlt ) {
14: $("#txt_Fade").fadeOut("slow", function () {
15: $(this).val("我飛OUT了");
16: })
17: }
18: });
19:
20: $(document).keyup(function (e) {
21: isAlt = false;
22: })
</script>
4:
5: </HEAD>
6: <BODY>
7: <FORM action="" id=form1 >
8: <input type="text" id="txt_Fade" value="" style="display:none"/><br />
9:
10: </FORM>
11: </BODY>
12: </HTML>