按钮单击不起作用

时间:2009-12-26 12:55:03

标签: javascript jquery json

以下代码运行良好。突然,“编辑”按钮单击停止工作。当用户用来单击“编辑”按钮时,会执行JSON代码。但它现在无法识别点击。偶然发生了什么事?请协助。

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
    <head>

        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"></meta>
        <script type="text/javascript" src="js/jquery.min.js"></script>
        <script type="text/javascript" src="js/jquery.cookie.js"></script>
        <script src="js/calendar.js" type="text/javascript"></script>
        <link href="js/calendar.css" type="text/css" rel="stylesheet" />
        <link rel="stylesheet" href="css/wysiwyg.css" type="text/css">
        <script type="text/javascript" src="js/wysiwyg.js"></script>
        <script type="text/javascript" src="js/wysiwyg-settings.js"></script>

        <!-- JSON implementation to get data through JQuery/AJAX -->
        <script type="text/javascript">
                $(document).ready(function(){
                    $("#Edit").click(function(){
                            $.getJSON("fetchvalues.php?UpdateRecordID=" + $.cookie('UpdateRecordID'),
                            function(data){

                            //Fill the Form with the data values    
                            document.getElementById('LDate').value = data[0];
                            document.getElementById('Places').value = data[1];
                            document.getElementById('Company').value = data[2];
                            document.getElementById('Designation').value = data[3];
                            document.getElementById('ProjectDetails').value = data[4];
                            document.getElementById('DesiredCandidate').value = data[5];
                            document.getElementById('HRName').value = data[6];
                            document.getElementById('HRContact').value = data[7];
                            document.getElementById('Email').value = data[8];
                        });
                    });
                });
        </script>

        <title>Job Listing Entry</title>
    </head>
    <body>
        <table id="main" cols="2">
        <tr>    
        <td>
        <Form id="frmNewEntry" method="post" action="insert_listing.php">
            <table id="tblEntry" cols="3" style="border-color:lightblue; border-style:solid;">
                <tr><td colspan="3" bgcolor="lightblue" align="center"><strong>Real-Time Vacancy Entry</strong></td></tr>
                <tr><td>Date:</td><td><input id="LDate" name="LDate" type="text" size="20" maxlength="11"/>[Select Date from the Calendar Control]
                    <script type="text/javascript">
                        WYSIWYG.attach('all', full);
                        calendar.set("LDate");
                    </script></td>
                    <td>
                        <table>
                            <tr>
                                <td rowspan="6">
                                <!--    <iframe src="show_db_vacancy_entries.php" height="800px" width="300px" bordercolor="cyan">

                                    </iframe> -->
                                </td>
                            </tr>
                        </table>
                    </td>
                </tr>
                <tr><td>Places:</td><td><input id="Places" name="Places" type="text" size="35" maxlength="30" onblur="this.value=MakeInitialCapital(this.value);"></td></tr>
                <tr><td>Company:</td><td><input id="Company" name="Company" type="text" size="50" onblur="this.value=MakeInitialCapital(this.value);">
                <!--    <input type="button" value="Make Initial Capital" align="left" onclick="this.value=MakeInitialCapital(this.value);"></tr> -->
                <tr><td>Designation:</td><td><input id="Designation" name="Designation" type="text" size="50" onblur="this.value=MakeInitialCapital(this.value);"></td></tr>
                <tr><td>Project Details:</td><td><textarea id="ProjectDetails" name="ProjectDetails" cols="100" rows="10"></textarea></td></tr>
                <tr><td>Desired Candidate:</td><td><textarea id="DesiredCandidate" name="DesiredCandidate" rows="3" cols="100"></textarea> <br></td></tr>
                <tr><td>HR Name:</td><td><input id="HRName" name="HRName" type="text" size="50" onblur="this.value=MakeInitialCapital(this.value);"> <br></td></tr>
                <tr><td>HR Contact:</td><td><input id="HRContact" name="HRContact" type="text" size="50"> <br></td></tr>
                <tr><td>Email:</td><td><input id="Email" name="Email" type="text" size="50"> <br></td></tr>
                <tr></tr>
                <tr>
                    <td  bgcolor="lightblue">
                        <input id="Clear" name="Clear" value="Clear" type="button" onclick="ClearFields();">
                    </td> 
                    <td bgcolor="lightblue">
                        <input id='Submit' name='Submit' value='Submit' type='submit' />
                    </td>
                </tr>

            </table>
        </Form>
        </td>
        <td>
            <table id="list" cols="2" style="border:none">
                <tr>
                    <td colspan="2" style="border:none">
                        <iframe src="show_db_vacancy_entries.php" height="600px" style="border:none;">

                        </iframe>
                    </td>
                </tr>
                <tr>
                    <td align="left">
                        <input id="Edit" name="Edit" value="Edit Record" type="button"  />
                    </td>
                    <td align="right">
                        <input id="Delete" name="Delete" value="Delete" type="button" />
                    </td>                   
                </tr>
            </table>
        </td>
        </tr>
        </table>
    </body>
</html>

<script language="JavaScript" type="text/javascript">
    function MakeInitialCapital(str)
    {
       return str.toLowerCase().replace(/\b[a-z]/g, cnvrt);
        function cnvrt() {
            return arguments[0].toUpperCase();
        }

    }

    //Convert initials to capital in a certain control
    function MakeInitialCapitalControl(controlName)
    {
    var ctrl = document.getElementById(controlName).value;

    if(/^[A-Z]/.test(ctrl.value)) {
        ctrl.value = ctrl.value.toLowerCase();
        return;
    }        

   /* ctrl.value = ctrl.value.toLowerCase().replace(/\b[a-z]/g, function {
        return arguments[0].toUpperCase();
    });*/
    }

    function ClearFields()
    {
        document.getElementById('Email').value = "";
        document.getElementById('HRContact').value = "";
        document.getElementById('HRName').value = "";
        document.getElementById('DesiredCandidate').value = "";
        document.getElementById('ProjectDetails').value = "";
        document.getElementById('Designation').value = "";
        document.getElementById('Company').value = "";
        document.getElementById('Places').value = "";
        document.getElementById('LDate').value = "";
    }

</script>

2 个答案:

答案 0 :(得分:0)

我删除了所有外部JS和CSS文件后测试了代码,它似乎工作正常。

问题很可能是你要回来的JSON数据。也许你对它正在调用的PHP文件做了一些事情,因此JSON对象格式不正确,或者打印了一个PHP警告。 (也可能是PHP配置发生变化的结果)

我建议您尝试在Firefox中使用Firebug插件激活(或等效的)。它将准确显示JSON请求返回的内容,以及请求是否有任何错误。

答案 1 :(得分:0)

正如Atli所说,代码看起来很好。我好奇这个$.cookie('UpdateRecordID'),是查询字符串的一部分。如果未设置cookie会发生什么?

你能通过萤火虫验证一个正确的反应吗?