问题描述
我有一个静态HTML,如下CSS开发人员所给出的
I have got a static HTML as shown below given by CSS developer
<div class="printHeader">
<div></div>
<div class="rest_head">
<h1 class="rest_name">Paris Restaurant</h1>
<h6 class="rest_adres">Opp. DBAFC Banck, FRIIUU, RAtech city, MAHERR - 500 081.<br> Phone: 9001 1156782</h6>
</div>
</div>
现在我的要求是,我需要在适用的地方附加动态值.
Now my requirement is that i need to append dynamic values where ever applicable .
我的问题是我应该动态创建HTML
My question is should i create a HTML dynamically
第一种方法
例如
动态创建以下div
<div></div>
<div class="rest_head">
<h1 class="rest_name">Paris Restaurant</h1>
<h6 class="rest_adres">Opp. DBAFC Banck, FRIIUU, RAtech city, MAHERR - 500 081.<br> Phone: 9001 1156782</h6>
</div>
and append it to printHeader
OR
第二种方法
Or should i just replace the values where ever applicable ??
What would be faster (Mine is a mobile application )
我在这里显示的HTML越小越好.请分享您的输入内容
The HTML i have shown here is smaller it is much more bigger .please share your inputs
推荐答案
我建议您遵循第二种方法
i will suggest you to follow your second approach
因为它对定制更友好
您可以将一些占位符用于## Address ##或@@ Address @@之类的动态值,只需在代码中替换这些值即可,它有两个好处
you can use some placeholder for dynamic values like ##Address## or @@Address@@ and just replace those values in your code it have two benefits
-
如果您更改HTML设计,则无需担心代码会正常工作
if you change your HTML design then you not need to worry about your code it will work fine,
分离代码和设计也很容易,因为我在Web应用程序中使用电子邮件模板时遇到相同的情况,并且使用了第一种方法,过了一段时间,每次UI更改都比我需要让我头疼相应地更改我的代码
it will be easy to separate your code and design as well i have same situation in web application for email template and used first approach and after some time it will be headache for me every time UI changed than i need to change my code accordingly
所以我建议第二种方法
这篇关于动态创建HTML还是仅在适用的情况下替换值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!