javascript - More modular; include html elements in .js file? -
I have a page that has many buttons to take action with JavaScript. There is no problem here, just an HTML page and multiple .js file, for each action to separate a .js file stuff and make everything a little more manageable. I will write a script to add them all together in the deployment.
Many of my JavaScript functions require html elements to work. For example, color.js needs a div with elements to change color so that the user can change the color and press the button to save the changes. Color.js does the function on-click buttons and in this way. there is no problem.
There are many JavaScript actions using many HTML elements, then there is a problem. All these HTML elements should be inserted into an HTML page. This makes things complicated, for example, when I change the color field ID, I have to make changes by going to color.js. Apart from this, I want to find html elements in my huge HTML page and also change it.
Can my javascript actions contain the required HTML elements in a .js file and somehow it can include it in my HTML page?
Of course I can escape all the HTML elements and put it in javascript variables and documents. Write it down But escaping is not a good thing and after this change of HTML is not very painful.
I am also not looking for an Ajax function, due to many different actions, it will create network problems.
Cheers for any ideas on the subject!
You can use template generate dynamic HTML via javascript
- Li>
- Data that fills the template (array, object)
- Settings for configuring a template engine
I have used some template engines, one of them is which is B is a friendly and easy to sugar-Syntax, usage, but low performance apply syntax.
The other template engine is in the library, which does not provide any sugar-syntax, but provides a basic JavaScript syntax, gives more power, and best performance.
The last experiment I used to do is . Future has a huge emphasis on performance on Glute. It will do business of "Syntax Sugar" convenient for better performance.
If you want to try more engines, here you can get a lot of them:
On the other hand, if you want to load a static HTML (for example a static view), you can use it to load data from Keep the server and the returned HTML in the matched element.
There is a short message of recommendation: Whatever options you choose, I use the cache I suggest either to save the scene or to save a compiled template, thus improving the performance of the same processing request.
Comments
Post a Comment