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.
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.
menudiv = document.createElement('div');
menudiv.className = 'menu';
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.
link = document.createElement('a');
link.setAttribute('href', 'urlFromYourJsonData');
link.appendChild(document.createTextNode('Your Link Description'));
menudiv.appendChild(link);
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:
div = document.createElement('div');
div.className = 'menu';
div.innerHTML = yourAjaxResponseHere;
精彩评论