这是我的Html:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd"
>
<html lang="en">
<head>
<title>Setlist</title>
<style type="text/css">
body{ }
</style>
</head>
<body>
<script type="text/javascript" src="javascripts/jquery-1.9.1.js"> </script>
<!-- Site navigation menu -->
<ul class="navbar">
</ul>
<button href="#" type="button" id="toggle">File Tools</button>
<div id="tools">
<P>Add a Set list:<br>
<LABEL for="labelName">Set List Name: </LABEL>
<INPUT type="text" name="slName" id="slname"><button id="createSL" value="Create Setlist">Create Set</button>
</P><br>
<P>Delete a Set list: (need to add functionality)<br>
<? include("remSLcombo.php"); ?> <button href="#" type="button" id="delSl">Delete Setlist</button>
</P>
</div><BR>
<? include("combo.php"); ?>
<script type="text/javascript">
$( document ).ready(function(){
$('#tools').hide();
$("#tunelist").change(function(e){
var test = $(this).val();
$.ajax({
type: "POST",
url: "new.php",
data: { database : test },
error: function(e){
alert(e.status);
},
success: function(response){
$('#display').html(response);
}
});
/*$(function(){
setInterval(function(){
$("#setlist").load("new.php");
}, 1 * 1000);
});*/
});
// toggles the slickbox on clicking the noted link
$('#toggle').click(function() {
$('#tools').toggle(400);
return false;
});
$('#createSL').click(function(){
var sendIt = $("#slName").val();
$.ajax({
type: "POST",
url: "createSL.php",
data: {slName : sendIt},
error: function(e){
alert("The PHP Call failed! hmmm");
alert(e.status);
},
success: function(response){
alert(response);
}
});
});
});
</script>
<div id= "display">
</div>
</body>
</html>
在功能$('#createSL').click(function()
中,当我单步执行该功能时,值sendIt
会显示undefined
。我究竟做错了什么?我是否遗漏了指向div的指针?
由于
答案 0 :(得分:4)
使用选择器时,ID属性区分大小写,尝试将输入的ID属性更改为“slName”(大写N)。
答案 1 :(得分:0)
jquery的选择器区分大小写,请尝试:var sendIt = $(“#slname”)。val();