2012-06-20 30 views
4

我想提出我的表格後,用戶點擊/觸摸複選框:複選框綁定change事件

的HTML

<input type="checkbox" name="chkSales" id="chkSales" class="custom" data-inline="true" data-mini="true"/><label for="chkSales">Sales</label>           
<input type="checkbox" name="chkArrival" id="chkArrival" class="custom" data-inline="true" data-mini="true"/><label for="chkArrival">New Arrival</label>               

的JS:

$("input[type='checkbox']").change(function() { 
    alert(e); 
    print(e); 
});​ 

從我在這裏閱讀它應該真的有用,但是ID doenst!我的問題在哪裏?

(應該是變化的,因爲移動設備不點擊,他們使用觸摸... http://jsfiddle.net/usTHG/2/

回答

16
$("input[type='checkbox']").change(function(e) { 
              ^---- you missed e here 
    alert(e.type); 
    print(e); 
});​ 

Working example

+2

10秒差異笑:) +1反正bruv! –

+0

@Tats_innit感謝隊友 – thecodeparadox

+0

現在這是偉大的@thecodeparadox。謝謝! – ItsMeDom

3

試試這個請:

你在您的功能中缺少ee

代碼

$("input[type='checkbox']").change(function(e) { 
    alert(e); 
    print(e); 
});​ 
1

嘗試:

$(document).ready(function() { 
     $("input[type='checkbox']").change(function(e) { 
      alert(e); 
      print(e); 
     }); 
    });