1

这是我的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 的指针或其他内容?

谢谢

4

2 回答 2

4

ID 属性在使用选择器时区分大小写,尝试将输入的 ID 属性更改为“slName”(大写 N)。

于 2013-03-04T02:27:04.043 回答
0

jquery 的选择器区分大小写,试试这个: var sendIt = $("#slname").val();

于 2013-03-04T02:39:37.780 回答