2017-08-02 18 views
0

HTML代碼的值:使用jQuery的地圖功能,以提醒複選框

<!DOCTYPE html> 
<html lang="en"> 
<head> 
<title>JobSeeker Registration Page </title> 
<meta charset="utf-8"> 
    <meta name="viewport" content="width=device-width, initial-scale=1"> 
    <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css"> 
    <script type="text/javascript" src="../jquery-1.11.3.min.js"></script> 
    <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script> 


    <script type="text/javascript" src="try.js"></script> 
</head> 
<body> 
<div> 
<form> 
<input type="checkbox" name="cb" value="First" /> First 
<input type="submit" value="Submit" id="sm" /> Submit 
</form> 
</div> 
</body> 

</html> 

jQuery代碼:

$(document).ready(function(){ 
    //alert("hello"); 

$("#sm").click(function(event){ 
    event.preventDefault(); 
    var searchIDs = 
    $(".cb:checked").map(function(){ 
     return $(this).attr('value');; 
    }).get(); 
    alert(searchIDs.join(',')); 
    }); 

}); 

我想提醒到瀏覽器的複選框的值。但沒有數據即將到來。任何人都可以告訴我上面的代碼有什麼問題。

回答

3

您還沒有在您的輸入中添加一個名爲.cb的類,因此您的選擇器從不會選取它們。

試試這個:

$("input[name=cb]:checked") 

或者添加缺少的類:

<input type="checkbox" name="cb" class="cb" value="First" /> First