2015-05-12 138 views
-1
$('input[name="list_checkbox_ids[]"], #frame, input[name="del_list_ids[]"]').on('keyup', function() { 
    $('#button_link').prop('disabled', ! $('input[name="list_checkbox_ids[]"]:checked').length); 
}); 

這種情況是,我點擊搜索按鈕,產生一個複選框列表。 button_link應默認爲disabled,直到我選中其中一個複選框。現在在上面的代碼中,Howcome它不會刪除disabled?我試圖在控制檯中查找錯誤,但找不到一個。請幫助。.keyup事件不起作用

list_checkbox_ids動態加載在頁面上。

+0

你檢查是否'$(「輸入[ name =「list_checkbox_ids []」],#frame,input [name =「del_list_ids []」]')'選擇文本類型的輸入(或類似) –

+0

你能提供html代碼嗎?使用它可以更容易地爲您提供幫助 –

+0

#frame是一個輸入字段 – ZSMJ

回答

0

你能不能改

$('input[name="list_checkbox_ids[]"], #frame, input[name="del_list_ids[]"]').on('keyup', function() { 
    $('#button_link').prop('disabled', !$('input[name="list_checkbox_ids[]"]:checked').length); 
}); 

進入這個(使用事件代表團)用於動態創建的內容

$(document).on('keyup','input[name="list_checkbox_ids[]"], #frame, input[name="del_list_ids[]"]', function() { 
    $('#button_link').prop('disabled', !$('input[name="list_checkbox_ids[]"]:checked').length); 
}); 
+0

發生同樣的事情。當我點擊複選框時,button_link將不會出現。 – ZSMJ

+0

在勾選複選框後,您是否在ID名稱爲「frame」的輸入欄中鍵入了某些內容?複選框勾選後,您的按鈕將顯示,並在輸入框中輸入ID爲'frame'的內容。如果你只是想通過勾選複選框來啓用按鈕,那麼'keyup'函數不適合,應該使用'click'事件來代替。嘗試這個小提琴http://jsfiddle.net/metallurgical/pamor1ay/1/ –

+0

嘗試此鏈接,看看發生了什麼http://jsfiddle.net/metallurgical/pamor1ay/2/ –