(function (jquery) {
//defined variable
var currentobj,
_getdata = function (opts, callback) {
jquery.ajax({
type: "post",
dataType: "text",
url: opts.requestdataurl,
cache: false,
data: { sfbcode: jquery("." + opts.names._codetxt).val() },
success: callback
});
},
//when code textbox value changed, trigger this event
_codechangeevent = function (opts) {
//if codetext onchange trigger
opts.onkeydown(jquery("." + opts.names._codetxt).val());
//------------------import---------------------------
if (opts.onlykeyboard)
currentobj.val(jquery("." + opts.names._codetxt).val());
else {
jquery("." + opts.names._resultsselect).empty();
//get data from server
_getdata(opts, function (data) {
var data = eval("(" + data + ")");
jquery(data).each(function (index, element) {
if (element.name != undefined)
jquery("." + opts.names._resultsselect).append("<option value='" + element.name + "'>" + element.name + "</option>");
});
});
}
},
//letter button event
_letterevent = function (opts) {
jquery("." + opts.names._letterbtn).bind("click",
function () {
if (opts.maxlength == null) {
jquery("." + opts.names._codetxt).val(jquery("." + opts.names._codetxt).val() + jquery(this).val());
_codechangeevent(opts);
}
else if (opts.maxlength != null && jquery("." + opts.names._codetxt).val().length < opts.maxlength) {
jquery("." + opts.names._codetxt).val(jquery("." + opts.names._codetxt).val() + jquery(this).val());
_codechangeevent(opts);
}
});
//clear button binding event.
jquery("." + opts.names._clearbtn).bind("click", function () {
jquery("." + opts.names._codetxt).val("");
if (currentobj != null) currentobj.val("");
});
},
//delete button click trigger
_deleteevent = function (opts) {
jquery("." + opts.names._delbtn).bind("mousedown", function () {
var val = jquery("." + opts.names._codetxt).val();
if (val.length != 0) {
val = val.substring(0, val.length - 1);
jquery("." + opts.names._codetxt).val(val);
_codechangeevent(opts);
}
});
},
//query button click
_queryevent = function (opts) {
// _getdata(opts, filldata);
},
//when click select item
_selectclickevent = function (opts) {
jquery("." + opts.names._resultsselect).bind("click",
function () {
if (currentobj != null) currentobj.val(jquery("." + opts.names._resultsselect).val());
});
},
//add class attribute to element
_addclstoele = function (cls, ele) {
if (cls != undefined)
ele.addClass(cls);
},
//create input control element
_createinputelement = function (type, cls, val) {
var element = jquery("<input type='" + type + "' />");
_addclstoele(cls, element);
if (val != undefined)
element.val(val);
return element;
},
//create div element
_createdivelement = function (cls) {
var element = jquery("<div />");
_addclstoele(cls, element);
return element;
},
//create keyboard button
_createkeyboard = function (container, opts) {
var i = 0;
//create 0-9 number
for (i = 0; i < 10; i++) {
container.append(_createinputelement("button", opts.names._letterbtn, i));
}
//create a-z word
for (i = 97; i < 123; i++) {
container.append(_createinputelement("button", opts.names._letterbtn, String.fromCharCode(i)));
}
//create A-Z word
if (!opts.simplekeyboard) {
for (i = 65; i < 92; i++) {
container.append(_createinputelement("button", opts.names._letterbtn, String.fromCharCode(i)));
}
}
},
//button bind event
_attachevent = function (opts) {
_letterevent(opts);
},
//restore keyboard
_restorekeyboard = function (opts) {
jquery("." + opts.names._codetxt).val("");
jquery("." + opts.names._resultsselect).empty();
},
//toggle visible
_visiblekeyboard = function (v, opts) {
if (v) {
jquery("." + opts.names._maindiv).css("left", currentobj.offset().left);
jquery("." + opts.names._maindiv).css("top", currentobj.offset().top + 20);
jquery("." + opts.names._maindiv).show();
_restorekeyboard(opts);
}
else {
jquery("." + opts.names._maindiv).hide();
_restorekeyboard(opts);
}
},
//Init face
_showkeyboard = function (opts) {
//get main content
// var content = jquery("."+opts.names._maindiv).hide();
var content = _createdivelement(opts.names._maindiv).css("position", "absolute").css("z-index", "9999").hide();
//create keyboard left panel
var skbleft = _createdivelement(opts.names._leftdiv)
.append(_createinputelement("text", opts.names._codetxt))
skbleft.append(jquery("<select />").addClass(opts.names._resultsselect).attr("multiple", opts.listmultiple));
//create keyboard right panel
var skbright = _createdivelement(opts.names._rightdiv);
//view or noview
skbleft = jquery(skbleft).css("display", opts.onlykeyboard == true ? "none" : "");
if (opts.onlykeyboard) skbright.css("float", "left");
//create keyboard toolbar of right panel
var skboperation = _createdivelement(opts.names._operationdiv)
.append(_createinputelement("button", opts.names._delbtn, opts.names._delbtnviewname))
.append(_createinputelement("button", opts.names._clearbtn, opts.names._clearbtnviewname))
.append(_createinputelement("button", opts.names._querybtn, opts.names._querybtnviewname))
.append(_createinputelement("button", opts.names._closebtn, opts.names._closebtnviewname).bind("click",
function () {
_visiblekeyboard(false, opts);
}));
//create keyboard
var skbkeyboard = _createdivelement(opts.names._keyboarddiv);
_createkeyboard(skbkeyboard, opts);
//attatch toobar to right panel
skbright.append(skboperation)
.append(skbkeyboard);
//attatch soft keyboard to HTML
content.append(skbleft);
content.append(skbright);
jquery("body").append(content);
//binding event
_attachevent(opts);
_selectclickevent(opts);
_deleteevent(opts);
};
//start pulgin
jquery.fn.softkeyboard = function (options) {
//merge parameters to opts
var opts = jquery.extend({}, jquery.fn.softkeyboard.defaults, options);
//Init keyboard to HTML page
_showkeyboard(opts);
//bind event to current element
this.each(function () {
jquery(this).bind("click", function () {
currentobj = jquery(this); //get current click object. --new
_visiblekeyboard(true, opts);
});
});
};
//default parameters
jquery.fn.softkeyboard.defaults = {
names: {
_delbtn: "skbdel",
_clearbtn: "skbclear",
_querybtn: "skbquery",
_closebtn: "skbclose",
_letterbtn: "skbbtn",
_maindiv: "skbsoftkeyboard",
_leftdiv: "skbleft",
_rightdiv: "skbright",
_keyboarddiv: "skbkeyboard",
_operationdiv: "skboperation",
_codetxt: "skbcode",
_resultsselect: "skbresults",
_postparamcode: "sfbcode",
_clearbtnviewname: "clear",
_delbtnviewname: "delete",
_querybtnviewname: "query",
_closebtnviewname: "close"
},
listmultiple: true, //keyboard results list is multiple? ture is multiple ,false is list
simplekeyboard: true, //simple keyboard dont create A-z letter only create 0-9,a-z
animation: false, //Animation effects for visible keyboard panel
onlykeyboard: false,
maxlength: null, //keyboard textbox allowed maximum length
requestdataurl: null,
oncompleted: function (data) { }, //When completed softkeyboard operation trigger the events
onkeydown: function (data) { } //when keydown(textbox change) trigger the events
};
})(jQuery);
请大家帮忙完善,现在仅仅是实现功能,布局什么的还没有弄好,所以请看到本文且有兴趣朋友帮忙完善,如有发现任何错误和不合理的地方请您反馈给我。分享快乐,快乐分享!(加载之前请先加载jquery)
//defined variable
var currentobj,
_getdata = function (opts, callback) {
jquery.ajax({
type: "post",
dataType: "text",
url: opts.requestdataurl,
cache: false,
data: { sfbcode: jquery("." + opts.names._codetxt).val() },
success: callback
});
},
//when code textbox value changed, trigger this event
_codechangeevent = function (opts) {
//if codetext onchange trigger
opts.onkeydown(jquery("." + opts.names._codetxt).val());
//------------------import---------------------------
if (opts.onlykeyboard)
currentobj.val(jquery("." + opts.names._codetxt).val());
else {
jquery("." + opts.names._resultsselect).empty();
//get data from server
_getdata(opts, function (data) {
var data = eval("(" + data + ")");
jquery(data).each(function (index, element) {
if (element.name != undefined)
jquery("." + opts.names._resultsselect).append("<option value='" + element.name + "'>" + element.name + "</option>");
});
});
}
},
//letter button event
_letterevent = function (opts) {
jquery("." + opts.names._letterbtn).bind("click",
function () {
if (opts.maxlength == null) {
jquery("." + opts.names._codetxt).val(jquery("." + opts.names._codetxt).val() + jquery(this).val());
_codechangeevent(opts);
}
else if (opts.maxlength != null && jquery("." + opts.names._codetxt).val().length < opts.maxlength) {
jquery("." + opts.names._codetxt).val(jquery("." + opts.names._codetxt).val() + jquery(this).val());
_codechangeevent(opts);
}
});
//clear button binding event.
jquery("." + opts.names._clearbtn).bind("click", function () {
jquery("." + opts.names._codetxt).val("");
if (currentobj != null) currentobj.val("");
});
},
//delete button click trigger
_deleteevent = function (opts) {
jquery("." + opts.names._delbtn).bind("mousedown", function () {
var val = jquery("." + opts.names._codetxt).val();
if (val.length != 0) {
val = val.substring(0, val.length - 1);
jquery("." + opts.names._codetxt).val(val);
_codechangeevent(opts);
}
});
},
//query button click
_queryevent = function (opts) {
// _getdata(opts, filldata);
},
//when click select item
_selectclickevent = function (opts) {
jquery("." + opts.names._resultsselect).bind("click",
function () {
if (currentobj != null) currentobj.val(jquery("." + opts.names._resultsselect).val());
});
},
//add class attribute to element
_addclstoele = function (cls, ele) {
if (cls != undefined)
ele.addClass(cls);
},
//create input control element
_createinputelement = function (type, cls, val) {
var element = jquery("<input type='" + type + "' />");
_addclstoele(cls, element);
if (val != undefined)
element.val(val);
return element;
},
//create div element
_createdivelement = function (cls) {
var element = jquery("<div />");
_addclstoele(cls, element);
return element;
},
//create keyboard button
_createkeyboard = function (container, opts) {
var i = 0;
//create 0-9 number
for (i = 0; i < 10; i++) {
container.append(_createinputelement("button", opts.names._letterbtn, i));
}
//create a-z word
for (i = 97; i < 123; i++) {
container.append(_createinputelement("button", opts.names._letterbtn, String.fromCharCode(i)));
}
//create A-Z word
if (!opts.simplekeyboard) {
for (i = 65; i < 92; i++) {
container.append(_createinputelement("button", opts.names._letterbtn, String.fromCharCode(i)));
}
}
},
//button bind event
_attachevent = function (opts) {
_letterevent(opts);
},
//restore keyboard
_restorekeyboard = function (opts) {
jquery("." + opts.names._codetxt).val("");
jquery("." + opts.names._resultsselect).empty();
},
//toggle visible
_visiblekeyboard = function (v, opts) {
if (v) {
jquery("." + opts.names._maindiv).css("left", currentobj.offset().left);
jquery("." + opts.names._maindiv).css("top", currentobj.offset().top + 20);
jquery("." + opts.names._maindiv).show();
_restorekeyboard(opts);
}
else {
jquery("." + opts.names._maindiv).hide();
_restorekeyboard(opts);
}
},
//Init face
_showkeyboard = function (opts) {
//get main content
// var content = jquery("."+opts.names._maindiv).hide();
var content = _createdivelement(opts.names._maindiv).css("position", "absolute").css("z-index", "9999").hide();
//create keyboard left panel
var skbleft = _createdivelement(opts.names._leftdiv)
.append(_createinputelement("text", opts.names._codetxt))
skbleft.append(jquery("<select />").addClass(opts.names._resultsselect).attr("multiple", opts.listmultiple));
//create keyboard right panel
var skbright = _createdivelement(opts.names._rightdiv);
//view or noview
skbleft = jquery(skbleft).css("display", opts.onlykeyboard == true ? "none" : "");
if (opts.onlykeyboard) skbright.css("float", "left");
//create keyboard toolbar of right panel
var skboperation = _createdivelement(opts.names._operationdiv)
.append(_createinputelement("button", opts.names._delbtn, opts.names._delbtnviewname))
.append(_createinputelement("button", opts.names._clearbtn, opts.names._clearbtnviewname))
.append(_createinputelement("button", opts.names._querybtn, opts.names._querybtnviewname))
.append(_createinputelement("button", opts.names._closebtn, opts.names._closebtnviewname).bind("click",
function () {
_visiblekeyboard(false, opts);
}));
//create keyboard
var skbkeyboard = _createdivelement(opts.names._keyboarddiv);
_createkeyboard(skbkeyboard, opts);
//attatch toobar to right panel
skbright.append(skboperation)
.append(skbkeyboard);
//attatch soft keyboard to HTML
content.append(skbleft);
content.append(skbright);
jquery("body").append(content);
//binding event
_attachevent(opts);
_selectclickevent(opts);
_deleteevent(opts);
};
//start pulgin
jquery.fn.softkeyboard = function (options) {
//merge parameters to opts
var opts = jquery.extend({}, jquery.fn.softkeyboard.defaults, options);
//Init keyboard to HTML page
_showkeyboard(opts);
//bind event to current element
this.each(function () {
jquery(this).bind("click", function () {
currentobj = jquery(this); //get current click object. --new
_visiblekeyboard(true, opts);
});
});
};
//default parameters
jquery.fn.softkeyboard.defaults = {
names: {
_delbtn: "skbdel",
_clearbtn: "skbclear",
_querybtn: "skbquery",
_closebtn: "skbclose",
_letterbtn: "skbbtn",
_maindiv: "skbsoftkeyboard",
_leftdiv: "skbleft",
_rightdiv: "skbright",
_keyboarddiv: "skbkeyboard",
_operationdiv: "skboperation",
_codetxt: "skbcode",
_resultsselect: "skbresults",
_postparamcode: "sfbcode",
_clearbtnviewname: "clear",
_delbtnviewname: "delete",
_querybtnviewname: "query",
_closebtnviewname: "close"
},
listmultiple: true, //keyboard results list is multiple? ture is multiple ,false is list
simplekeyboard: true, //simple keyboard dont create A-z letter only create 0-9,a-z
animation: false, //Animation effects for visible keyboard panel
onlykeyboard: false,
maxlength: null, //keyboard textbox allowed maximum length
requestdataurl: null,
oncompleted: function (data) { }, //When completed softkeyboard operation trigger the events
onkeydown: function (data) { } //when keydown(textbox change) trigger the events
};
})(jQuery);
请大家帮忙完善,现在仅仅是实现功能,布局什么的还没有弄好,所以请看到本文且有兴趣朋友帮忙完善,如有发现任何错误和不合理的地方请您反馈给我。分享快乐,快乐分享!(加载之前请先加载jquery)
相关推荐
总的来说,JS软键盘的实现涉及了JavaScript基础、DOM操作、事件处理、CSS样式和浏览器兼容性等多个方面。通过深入理解这些技术并结合具体应用场景,我们可以创建出满足各种需求的JS软键盘,提供流畅且安全的在线输入...
重要的是,这个软键盘不依赖任何外部插件,这意味着它的实现完全基于纯JavaScript和HTML,这有利于代码的轻量化和跨平台兼容性。同时,它可以被自定义样式,允许开发者根据自己的应用设计进行定制,以保持界面的一致...
本文将深入探讨jQuery数字软键盘这一主题,它是一个专为输入纯数字设计的虚拟键盘,不包含英文字母。 jQuery是一种广泛使用的JavaScript库,它简化了DOM操作、事件处理和动画制作等多个方面的工作。对于数字软键盘...
6. CSS操作:JavaScript也可以用于修改CSS样式,实现软键盘的外观定制。 7. 安全性:JavaScript还可以用于防止某些安全威胁,例如XSS(跨站脚本攻击)或键盘记录器。 【压缩包子文件的文件名称列表】 "softkey-...
为了实现JavaScript软键盘,开发者需要掌握以下关键知识点: 1. DOM操作:利用JavaScript对HTML元素进行增删改查,如创建新的DOM元素(按钮)、设置元素属性(如按钮上的文字和点击事件处理函数)以及获取用户与...
在Vue.js中实现移动端H5数字键盘组件是一个常见的需求,特别是在开发支付或输入数字的场景中。本篇文章将深入解析如何构建这样一个自定义组件,并提供详细的代码示例,以帮助开发者理解和实现自己的数字键盘组件。 ...
2. **jQuery驱动**:基于流行的JavaScript库jQuery构建,使得键盘功能的实现更加简洁、高效,兼容性好,能轻松集成到现有的Web应用中。 3. **用户体验**:虚拟键盘的交互设计考虑了触摸屏操作,键位布局合理,响应...
在本文中,我们将深入探讨如何使用纯JavaScript和CSS来实现一个仿移动端淘宝网站的弹出详情框功能。这个功能在很多电商应用中都非常常见,它允许用户点击某个商品时,弹出一个展示商品详情的窗口,而不离开当前页面...
8. **指针表,纯JavaScript实现.html** - 指针表通常用于数据处理和搜索,这里的纯JavaScript实现可能涉及到数组操作、数据结构和搜索算法的实践。 9. **漂亮淡蓝色滑动门代码.html** - “滑动门”是一种CSS布局...
- "纯JS控制DIV选择范围移动与复制.htm"可能涉及到HTML5的拖放API,让用户能够选择、移动和复制网页上的DOM元素。 以上就是压缩包中所涵盖的JavaScript知识点,每个文件都是一个具体的应用示例,开发者可以通过研究...
11. **用户交互**:纯代码实现的3D动画可与用户输入(如键盘、鼠标或触摸)交互,改变视角、动画状态等。 12. **碰撞检测**:为了实现物体间的交互,碰撞检测算法是必不可少的,它可以帮助判断两个物体是否相碰。 ...
这可以通过在网站上显示提示信息或者使用渐进增强的策略来实现。 在处理这个问题时,开发者需要平衡兼容性与性能,选择最适合项目需求的方法。同时,随着技术的发展,越来越少的用户会使用IE6,因此在新的项目中,...
- **知识点**:操作系统是计算机系统的核心组成部分,它具有三大主要功能:一是作为软硬件资源的管理者,二是作为用户与计算机硬件之间的接口,三是提供软件的开发和运行环境。 #### 29. 宏操作的范围 - **知识点**...
中断方式和直接内存访问(DMA)方式均能实现I/O设备与主机的数据交换,但DMA方式更适用于高速数据传输,因为它允许I/O设备直接与内存交换数据,无需CPU干预,从而提高了数据处理速度。相比之下,中断方式需要CPU执行...