iPhone webapp design
In my iPhone webapp, I have a blank div and I add things to it dynamically using:
var example=$(document.createElement('which-ever-tag i need'));
example.html('blah blah')
blank_div.append(example);
This way I can add and remove elements as I need.
example.remove();
I recently thought though, I can also do it this way from my initial HTML page:
<div id='homepage'>
place some content in here
</div>
<div id='second_page'>
some more content
</div>
And then I can hide and unhide certain sections. I was just wondering what would be the best way to do this?
JavaScript to dynamically create the elements, or to have them made and just unhide when ever to show a section needed?
Code snippet:
title=$(document.createElement('div'));
title.addClass('title');
title.html('Mango Fitness');
container.append(title);
I'd say it's a matter of preference, with pros and cons for each. Using JavaScript, you keep all your pieces in one (perhaps) neat file. By splitting it up, though, you can separate your main view layouts from your logic, perhaps making it easier to work with later. I personally prefer using HTML for layout, and JavaScript for controller logic.
链接地址: http://www.djcxy.com/p/42592.html下一篇: iPhone的webapp设计