在2个按钮上单击事件,使用jQuery获取未按下按钮的值

时间:2012-08-15 18:59:02

标签: javascript jquery html dom javascript-events

我有2个按钮,我分配了一个事件。我知道如何捕获单击按钮上的值,但不知道未单击的按钮上的值。任何想法都将不胜感激。

var $b1 = $('<input/>', { 'type': 'button', 'value': '0' });
var $b2 = $('<input/>', { 'type': 'button', 'value': '1' });
var $bm = $b1.add($b2);  
$myDiv.append($bm);      
$bm.on('click', function() {         
    var clicked = $(this).val();
    var not_clicked = ???

1 个答案:

答案 0 :(得分:4)

使用.not()过滤掉当前点击的输入

$bm.on('click', function() {         
var clicked = $(this).val();
var not_clicked = $bm.not(this).val();  
// select both buttons.. filter out current clicked with not().. get val()
相关问题