我有以下 ejs 模板
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Emasc Editor</title>
<style>
.list{
display: inline-block;
}
</style>
<script type="text/javascript" src="/js/jquery-1.7.1.min.js"></script>
<script type="text/javscript">
$(document).ready(function(){
alert('test');
$("#setMembershipsButton").click(function(e){
// send selected person and groups to server and create memberships
data = {
person: $('#person_list').val(),
groups: $('#group_list').val()
};
$.post('/newConnections', data);
});
$("#person_list").change(function(){
alert('test');
// send selected person to server and retrieve memberships
$.post('/getPersonGroups', { personID: $('#person_list').val() }, function(data, textStatus){
$('#group_list option').removeAttr('selected');
for(var i=0; i<data.ids.length; i++){
$('#group_list option[value=' + data.ids[i] + ']').attr('selected', 'selected');
}
});
});
});
</script>
</head>
<body>
<div class="list">
<select id="person_list" size="<%= persons.length+1 %>">
<% for( var i=0; i<persons.length; i++){ %>
<option value="<%= persons[i].id %>"><%= persons[i].name %></option>
<% } %>
</select>
<form method="post" action="/newPerson">
<input type="text" name="user[name]" />
<input type="submit" value="Submit" />
</form>
</div>
<div class="list">
<select id="group_list" multiple size="<%= groups.length+1 %>">
<% for( var i=0; i<groups.length; i++){ %>
<option value="<%= groups[i].id %>"><%= groups[i].name %></option>
<% } %>
</select>
<form method="post" action="/newGroup">
<input type="text" name="group[name]" />
<input type="submit" value="Submit" />
</form>
</div>
<br/>
<input id="setMembershipsButton" type="button" value="Set Memberships"></input>
</body>
</html>
并且第一个 alert('test') 永远不会被调用。我在这里想念什么?