博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
在web page中按enter鍵焦點轉到下一個tabindex的控件
阅读量:4041 次
发布时间:2019-05-24

本文共 2607 字,大约阅读时间需要 8 分钟。

實現功能:使用Ajax在webpage中按enter鍵轉到下一個tabindex值加1的控件,方便用戶連續輸入.

一.首先建立轉到下一個tabindex控件的 js function.保存為一個js file,在需要的頁面進行引入

function轉自:Lysender’s Daily Log Book - Enter to tab navigation jQuery plugin

/** Copyright (c) 2007 Betha Sidik (bethasidik at gmail dot com)* Licensed under the MIT License:* http://www.opensource.org/licenses/mit-license.php** This plugin developed based on jquery-numeric.js developed by Sam Collett (http://www.texotela.co.uk)*//** Change the behaviour of enter key pressed in web based to be tab key* So if this plugin used, a enter key will be a tab key* User must explicitly give a tabindex in element such as text or select* this version will assumed one form in a page* applied to element text and select**//** I modified the plugin to work for my need* This will work even if the next tabindex is non-existent, or disabled so* it will find the very next element on the tabindex series until the maximum tabindex* which must be defined manually.** ALL CREDITS GOES TO THE ORIGINAL AUTHOR*/jQuery.fn.enter2tab = function () {
this.keypress(function (e) {
// get key pressed (charCode from Mozilla/Firefox and Opera / keyCode in IE) var key = e.charCode ? e.charCode : e.keyCode ? e.keyCode : 0; var tmp = null; var maxTabIndex = 9999; // get tabindex from which element keypressed var nTabIndex = this.tabIndex + 1; // get element type (text or select) var myNode = this.nodeName.toLowerCase(); // allow enter/return key (only when in an input box or select) if (nTabIndex > 0 && key == 13 && nTabIndex <= maxTabIndex && ((myNode == "textarea") || (myNode == "input") || (myNode == "select") || (myNode == "a"))) {
for (var x = 0; x < 3; x++) {
tmp = $("a[tabIndex='" + nTabIndex + "'],textarea[tabIndex='" + nTabIndex + "'],select[tabIndex='" + nTabIndex + "'],input[tabIndex='" + nTabIndex + "']").get(0); if (typeof tmp != "undefined" && !$(tmp).attr("disabled")) {
$(tmp).focus(); return false; //break; } else {
//如果要循環的話,就解開以下的封印 //var first = $("a[tabIndex='1'],textarea[tabIndex='1'],select[tabIndex='1'],input[tabIndex='1']").get(0); //$(first).focus(); return false; } } return false; } else if (key == 13) {
return false; } }) return this;}

二,web page

    

转载地址:http://dpmdi.baihongyu.com/

你可能感兴趣的文章
所谓的进步和提升,就是完成认知升级
查看>>
为什么读了很多书,却学不到什么东西?
查看>>
长文干货:如何轻松应对工作中最棘手的13种场景?
查看>>
如何用好碎片化时间,让思维更有效率?
查看>>
No.147 - LeetCode1108
查看>>
No.174 - LeetCode1305 - 合并两个搜索树
查看>>
No.175 - LeetCode1306
查看>>
No.176 - LeetCode1309
查看>>
No.182 - LeetCode1325 - C指针的魅力
查看>>
mysql:sql alter database修改数据库字符集
查看>>
mysql:sql truncate (清除表数据)
查看>>
yuv to rgb 转换失败呀。天呀。谁来帮帮我呀。
查看>>
yuv420 format
查看>>
YUV420只绘制Y通道
查看>>
yuv420 还原为RGB图像
查看>>
LED恒流驱动芯片
查看>>
驱动TFT要SDRAM做为显示缓存
查看>>
使用file查看可执行文件的平台性,x86 or arm ?
查看>>
qt5 everywhere 编译summary
查看>>
qt5 everywhere编译完成后,找不到qmake
查看>>