使用 json、Html、JS 和 创建动态菜单移动平台的CSS
我使用 html、js 和 json 对象(从服务器下载)创建动态菜单。 请
我读到“document.write 不应在 onLoad() 或 onclick() 等事件处理程序中使用。最好使用 DOM”,
提供您宝贵的建议。
Am creating a dynamic menu from json object(downloaded from server) using html, js & css for mobile platforms without using libraries like JQuery
i read like "document.write should not be used in event handlers like onLoad() or onclick() . its better to use DOM"
plz give your valuable suggestions.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以通过 .createElement() 方法使用 DOM 在 javascript 中创建元素。
示例:为您的菜单创建一个 div 并为其指定一个 css 类名称。
现在您可以通过创建其他元素将 json 数据插入其中。例如,如果您想使用 DOM 创建链接。
等等...
我建议您看一下: https://developer.mozilla .org/en/DOM/document.createElement 并从那里开始。
编辑:看到你的第二条评论后,我还建议你看看 http://json.org 来查找 JSON是。如果您想将 HTML 代码复制到页面中,您应该使用
innerHTML
属性。例子:
You can create elements in javascript using DOM by using the .createElement() method.
Example: Create a div for your menu and give it a css class name.
Now you can plug your json data into it by creating other elements. For example if you would like to create a link using DOM.
and so on ...
I suggest you have a look at: https://developer.mozilla.org/en/DOM/document.createElement and make your way from there.
Edit: After seeing your second comment I also suggest you have a look at http://json.org to look up what JSON is. If you want to copy HTML code into your page you should use the
innerHTML
attribute.Example: