多个属性选择器jQuery的操作 [英] Action with Multiple Attribute Selector jQuery

查看:138
本文介绍了多个属性选择器jQuery的操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用键盘输入数字值。

I am trying to use a keyboard to enter numeric values.

我的问题如下:键盘有一个按钮接受,我有几个文本字段,我想为每个文本字段添加不同的操作。我尝试使用多个属性选择器但不工作。

My problems is the following: the keyboard has a button "Accept" and I have several text fields, I want to add for each text fields a different action. I tried to use multiple attribute selector but is not work.

<input id="txt1" type="text" /> </br>
<input id="txt2" type="text" /> </br>
<input id="txt3" type="text" /> </br>







$('input[type=text]').keyboard({
    layout: "num"
});

$('.ui-keyboard').on('click', 'input[name="key_accept"]',function() {
    alert('Accept button was clicked in text1');
    // do your stuff here
});

您可以在此链接中显示示例 http://jsfiddle.net/Mils/W2xFX/25/

You can show the example in this link http://jsfiddle.net/Mils/W2xFX/25/

推荐答案

由于您使用的组件不会公开任何事件接受和取消,需要一个外部解决方案。例如,您可以将当前元素保存在焦点上,并在接受按钮事件中使用。

Since the component you are using does not expose any event for accept and cancel, an external solution is needed. For example, you can save the current element on focus, and use that inside the accept button event.

演示: http://jsfiddle.net/W2xFX/27/

代码:

var currentKB = null;
$('input[type=text]').focus(function() {
    currentKB = this;
    return true;
});

$('input[type=text]').keyboard({
    layout: "num"
});

$('.ui-keyboard').on('click', 'input[name="key_accept"]',function(e, x) {
    alert('Accept button was clicked in ' + currentKB.id);
    // do your stuff here
});

这篇关于多个属性选择器jQuery的操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆