将html或div的内容加载到div中

时间:2015-09-06 05:35:25

标签: javascript jquery html

我有一套“li”。点击每个“li”时,我想加载一个带有html页面内容的“div”。我已经在stackoverflow&中读到了一些答案。尝试了他们,但他们没有帮助我让这个工作。

这是我现在正在尝试的代码

<!doctype html>
<html lang=''>
   <head>
      <meta charset='utf-8'>
      <meta http-equiv="X-UA-Compatible" content="IE=edge">
      <meta name="viewport" content="width=device-width, initial-scale=1">
      <link rel="stylesheet" href="styles.css">
      <script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
      <script type="text/javascript">
      $(document).ready(function(){
         $("#page1").click(function(){
            $('#result').load('dst.html');
           //alert("Thanks for visiting!");
         }); 

         $("#page2").click(function(){
            $('#result').load('incf.html');
           //alert("Thanks for visiting!");
         });
       });
   </script>
   </head>
   <body>
      <header class="site-header-wrap">
         <div class="site-header">
            <h1>MY TOOL</h1>
         </div>
      </header>
      <div id='cssmenu'>
         <ul>
            <li class='active'><a href='#'><span>HOME</span></a></li>
            <li><a id="page1" href="#"><span>OPTION 1</span></a></li>
            <li><a id="page2" href="#"><span>OPTION 2</span></a></li>
            <li><a id="page3" href="#"><span>OPTION 3</span></a></li>  
         </ul>
      </div>
      <div id="result"></div>
   </body>
<html>

dst.html中的代码是

<html lang=''>
   <body>
      <p> In page 1(dst page) </p>
   </body>
<html>

我可以请求帮助,请发现我在这里做错了吗?

1 个答案:

答案 0 :(得分:1)

您的代码似乎对我来说很有用,我在代码中更改的唯一内容是#include<stdio.h> int main(){ char n4m3[100],Pos; int rt,hr,gI,T,td,ss=100,pi=100,hc=100,NetIn; printf(" ==Employee Salary=="); printf("\n Name:"); scanf(" %s",&n4m3); printf("\n -Position- \n C-CEO\n V-VP\n S-Supervisor\n T-Team Leader"); printf("\n Postion:"); scanf(" %s",&Pos); if (Pos=='C'||Pos=='c') { rt=500; printf("\n CEO Rate:500"); } else if (Pos=='V'||Pos=='v') { rt=400; printf("\n VP Rate:400"); } else if (Pos=='S'||Pos=='s') { rt=300; printf("\n Supervisor Rate:300"); } else if (Pos=='T'||Pos=='t') { rt=200; printf("\n Team Leader Rate:200"); } else printf(" Invalid Input"); printf("\n Number of Hours Worked:"); scanf("%d",&hr); printf("\n ==Summary=="); gI=rt*hr; printf("\n Gross Income:%d",gI); if (gI>=4000) T=gI*.4; else if (gI>=3000) T=gI*.3; else if (gI>=2000) T=gI*.2; else if (gI>=1000) T=gI*.1; printf("\n Tax:%d",T); td=T+ss+pi+hc; printf("\n Total Deductions:%d",td); NetIn=gI-td; printf("\n Net Income is %d",NetIn); printf("\n----------------------"); printf("\n Mr./Ms. %s your net income is %d",n4m3,NetIn); } $('#dblock').load('dst.html');,因为没有ID为$('#result').load('dst.html');的div

还要确保你的文件结构设置正确并且html文件在那里你已经设置了你现在应该在同一个文件夹中有三个html文件