需要通过点击菜单将html页面显示为div标签内容 [英] need to display html page into div tag content by click menu

查看:346
本文介绍了需要通过点击菜单将html页面显示为div标签内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此代码用于菜单。如果我点击这个菜单; div内容可以加载html页面。同样的事情我会点击另一个菜单;相同的div内容可以加载另一个html页面。

this code is for menu. if i click this menu; the div content can load the html page. by same thing i will click another menu; the same div content can load the another html page.

<li>
  <div align="center"><a href=# class="style15" onclick="divload()">IEEE Projects</a></div>
</li>
<li>







这是功能码






this is function code

<script type="text/javascript">
  function divload()
{
  document.getElementById("article").innerHTML = "test.html";
  }
  </script>







任何人都帮我...




anyone help me...

推荐答案

首先,根据页面的定义,页面不能是元素的一部分。 :-)



当然,你可以在 div 元素中包含任何HTML内容;你几乎得到了它。只有当您通过 id 找到元素时,该元素才应具有此 id ,在本例中为article。例如,

First of all, a page cannot be a part of an element, by definition of a page. :-)

Of course, you can have any HTML content inside div element; and you almost got it. Only if you find an element by id, that element should have this id, in this case, "article". For example,
<div id="article" onclick="divload()">Click here...</div>





顺便说一下,你的属性 align =center是一件坏事。你需要使用CSS代替。你的命名如style15也很糟糕。你打算如何支持它?所有名称都应具有语义意义。



-SA



By the way, your attribute align="center" is quite a bad thing. You need to use CSS instead. Your naming like "style15" is also quite bad. How are you going to support it? All names should be semantically meaningful.

—SA


Berhanu sahle问:
Berhanu sahle asked:

这有效但当我重新加载浏览器时,div丢失了它的数据......我怎么能解决它...

this works but when i reload my browser, the div loses its data… how can i fix it…

当然。如果需要保留数据,则需要在加载页面后对其进行序列化,存储和还原。由于问题是关于纯HTML + JavaScript,最好的通用方式是使用本地Web存储: http://en.wikipedia.org / wiki / Web_storage



使用会话存储 sessionStorage 对象非常重要,而不是本地存储。本地存储是永久性的;我们不想污染本地浏览器数据。现在,另一个问题是:一个键存储的数据应该是字符串,我想存储封装两个控件状态的对象,其中一个状态值是布尔值。为此,我使用了嵌入在JavaScript中的JSON序列化: https:// developer。 mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON



我在动态严格一节中解释解决方案模式切换和网络存储我的文章 JavaScript Calculator



您将完整地找到完整的代码示例。您还可以下载游戏的完整源代码,只需在一个HTML中使用两个JavaScript文件。




祝贺4月1日! :-)



我想利用这个机会邀请大家看一下我4月份新发布的1并有一些乐趣:



某些编程方法神经语言程序设计

特别鼓励在评论和讨论中参与此游戏。



谢谢。

-SA

Of course. If you need to preserve data, you need to serialize it, store it, and restore after the page is loaded. As the question is about pure HTML+JavaScript, the best universal way would be using local Web storage: http://en.wikipedia.org/wiki/Web_storage.

It is important to use session storage sessionStorage object, and not local storage. Local storage is permanent; and we don't want to contaminate local browser data. Now, another problem is: data stored by one key should be string, and I want to store the object encapsulating the states of both controls, one of these state values being Boolean. For this purpose, I utilized JSON serialization embedded in JavaScript: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON.

I explain the solution in the section "Dynamic Strict Mode Switching and Web Storage" of my article JavaScript Calculator.

You will find a complete code sample covering this technique completely. You can also download the whole source code for the game, with is just two JavaScript files used in one HTML.



Congratulations with 1st of April! :-)

I would like to use the occasion to invite everyone to see my new 1 of April publication and have some fun:

Some Programming Approaches to "Neuro-Linguistic Programming".
Participation in this game in Comments and Discussions is especially encouraged.

Thank you.
—SA


这篇关于需要通过点击菜单将html页面显示为div标签内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆