为什么我不能改变div的内容?

时间:2014-09-19 15:47:52

标签: jquery html

美好的一天,我的问题是,当我在MainScreen.html中时,我无法更改 EmployeeInformation.html 的div内容,即“Emps” div,通过使用jquery加载 Personal.html 的内容而具有“DDDDDDDDDDDDDDDDDDDDD”。

步骤是: 在MainScreen.html中,单击“?EmployeInformation”,然后单击“?QQQQ”链接。

MainScreen.html

<!DOCTYPE html>
<html>
    <head>
        <link href="./MainScreen.css" rel="stylesheet" type="text/css">
        <script src="./Jquery/dev/jquery-2.1.1.js"></script>
        <script src="./MainScreen.js"></script>
    </head>
    <body>
        <div id="AccountHeader">
            CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
            <br>
            CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
        </div>
        <div id = "HeaderImage">
            <img src="./Images/header.jpg">
        </div>
        <div id="MenuList">
            <ul id="NavigationBar">
                <li><button>Notifications</button></li>
                <li><button>File Maintenance</button></li>
                <li><button>Transaction</button></li>
                <li><button>Reports</button></li>
            </ul>
        </div>
        <div id="LeftPanel">
            <ul id="FileMaintenanceMenu">
                <li><a href="#">?Authorized Overtime Schedule</a></li>
                <li><a href="#">?Bank</a></li>
                <li><a href="#">?Calendar of Length of Service</a></li>
                <li><a href="#">?Degree</a></li>
                <li><a id = "link" href="#">?EmployeeInformation</a></li>
                <li><a href="#">?Employees with Evening Service</a></li>
                <li><a href="#">?Employees with Extra Load</a></li>
                <li><a href="#">?Function</a></li>
                <li><a href="#">?Honorarium of Coaches</a></li>
                <li><a href="#">?Mode of Salary</a></li>
                <li><a href="#">?Non-Working and Special Holiday</a></li>
                <li><a href="#">?Parameter File</a></li>
                <li><a href="#">?Part-time Employees</a></li>
                <li><a href="#">?Plantilla</a></li>
                <li><a href="#">?Position</a></li>
                <li><a href="#">?Public Holiday</a></li>
                <li><a href="#">?Salary Schedule</a></li>
                <li><a href="#">?Special Projects</a></li>
                <li><a href="#">?Status of Employment</a></li>
                <li><a href="#">?Student Assistant</a></li>
                <li><a href="#">?Titles/ Designation</a></li>
                <li><a href="#">?User/ Password Maintenance</a></li>
                <li><a href="#">?Withholding Tax Table</a></li>
            </ul>
            <br>AAAAAAAAAAAAAAAAA
            <br>AAAAAAAAAAAAAAAAA
            <br>AAAAAAAAAAAAAAAAA
            <br>AAAAAAAAAAAAAAAAA
            <br>AAAAAAAAAAAAAAAAA
            <br>AAAAAAAAAAAAAAAAA
            <br>AAAAAAAAAAAAAAAAA
            <br>AAAAAAAAAAAAAAAAA
            <br>AAAAAAAAAAAAAAAAA
            <br>AAAAAAAAAAAAAAAAA
            <br>AAAAAAAAAAAAAAAAA
            <br>AAAAAAAAAAAAAAAAA
            <br>AAAAAAAAAAAAAAAAA
            <br>AAAAAAAAAAAAAAAAA
            <br>AAAAAAAAAAAAAAAAA
        </div>
        <div id="RightPanel">
            <br>BBBBBBBBBBBBBBBBBBBBBBBBB
            <br>BBBBBBBBBBBBBBBBBBBBBBBBB
            <br>BBBBBBBBBBBBBBBBBBBBBBBBB
            <br>BBBBBBBBBBBBBBBBBBBBBBBBB
            <br>BBBBBBBBBBBBBBBBBBBBBBBBB
            <br>BBBBBBBBBBBBBBBBBBBBBBBBB
            <br>BBBBBBBBBBBBBBBBBBBBBBBBB
            <br>BBBBBBBBBBBBBBBBBBBBBBBBB
            <br>BBBBBBBBBBBBBBBBBBBBBBBBB
            <br>BBBBBBBBBBBBBBBBBBBBBBBBB
            <br>BBBBBBBBBBBBBBBBBBBBBBBBB
            <br>BBBBBBBBBBBBBBBBBBBBBBBBB
            <br>BBBBBBBBBBBBBBBBBBBBBBBBB
        </div>
    </body>
</html>

MainScreen.js

$( document ).ready(function() {    

    $("#link").click(function()
    {
        alert('a');
            $("#RightPanel").load("./FileMaintenance/EmployeeInformation.html"); 
    });
});

EmployeeInformation.html

<!DOCTYPE html>
<html>
    <head>

        <script src="../Jquery/dev/jquery-2.1.1.js"></script>
        <script src="./EmployeeInformation.js"></script>
    </head>
    <body>
        <form id = "BasicInfo" method="post" action="EmployeeInformation.html">
            <span class = "FieldLabels">ID Number</span> <input type="text" id="IdNumber">
            <br>
            <input type="text" id="LastName">&nbsp;&nbsp;&nbsp;
            <input type="text" id="FirstName">&nbsp;&nbsp;&nbsp;
            <input type="text" id="MiddleName">
            <br>
            <span class = "FieldLabels">Last Name</span>
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <span class = "FieldLabels">First Name</span>
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <span class = "FieldLabels">Middle Name</span>

        </form>
        <ul id = "EmployeeInfoTabs">
            <li><a id = "the" href="#" onclick="alert('b')">?QQQQ</a></li>
            <li><button>?Personal</button></li>
            <li><button>?Employment</button></li>
            <li><button>?Payroll Info</button></li>
            <li><button>?Family and Other Info</button></li>
            <li><button>?Previous Employment</button></li>
        </ul>
        <div id= "Emps">DDDDDDDDDDDDDDDDDDDDDDDDDDD</div>
    </body>
</html>

MainScreen.js

$( document ).ready(function() {

    $("#the").click(function()
    {
        alert('c');
            $("#Emps").load("./EmployeeInformation/Personal.html"); 
    });
});

Personal.html

<!DOCTYPE html>
<html>
    <head>
        <script src="../../Jquery/dev/jquery-2.1.1.js"></script>
    </head>
    <body>
        <div id= "aaaaa">AAAAAAAAAAAAAAAAAAAAAAAAAAA</div>
    </body>
</html>

我的错误是什么?

我也尝试手动转到“EmployeeInformation.html”,它可以工作,它将“DDDDDDDDDDDDDDD”更改为“AAAAAAAAAAAAAA”但是,如果我在MainScreen.html中它不起作用,为什么?

步骤是MainScreen.html,单击“?EmployeInformation”,然后单击“?QQQQ”链接。

顺便说一句,我想在这里直接上传一张图片,但我的声望点不到10 :(

所以,这是图片的链接:

文件和文件夹的目录: https://onedrive.live.com/redir?resid=20796C7633AE90D!233&authkey=!ACNqvIRZeJYPMkE&v=3&ithint=photo%2cJPG

MainScreen.html https://onedrive.live.com/redir?resid=20796C7633AE90D!235&authkey=!AJrxTsF0sugU-eE&v=3&ithint=photo%2cJPG

感谢您的帮助:D

1 个答案:

答案 0 :(得分:0)

如果没有任何代码可以查看,我将从一个基本答案开始。

假设您有权访问DIV,这里是如何使用jQuery更改其内容,您似乎正在使用它:

这是一个具有唯一ID的div:

<div id="mydiv">DDDDDDDDDDDDD</div>

这是改变它的代码:

$("#mydiv").html("EEEEEEEEEEEEE");

您还可以使用html()来获取元素的内容。