动态添加HTML的最佳方法 [英] Best method to add HTML dynamically

查看:60
本文介绍了动态添加HTML的最佳方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


Javascript新手,想要学会做正确的事情。


我有动态表这是使用Javascript填充的。目前我正在寻找使用W3C DOM添加节点,但这些看起来很漂亮,特别是添加所有属性等等。


有没有办法在一堆HTML文本中bla,,或者这个皱眉头现在是什么?


干杯,
Lister

解决方案

li ************ @ hotmail.com 在2006年10月22日下午5:49发表以下内容:


大家好,


Javascript新手,想要学会做正确的事情。


我有一个动态表,使用Javascript填充。目前我正在寻找使用W3C DOM添加节点,但这些看起来很漂亮,特别是添加所有属性等等。


有没有办法在一堆HTML文本中bla,,或者这件事现在已经皱起了什么?b $ b?



在FAQ小组中使用DynWrite。

< URL:http://jibbering.com/faq/#FAQ4_15>


-

兰迪

机会有利于准备好的心灵

comp.lang.javascript常见问题 - http://jibbering.com/faq &新闻组每周

Javascript最佳实践 - http://www.JavascriptToolbox .com / bestpractices /


Randy Webb写道:

li ************ @ hotmail.com 在2006年10月22日下午5:49发表以下内容:


大家好,


Javascript新手,想要学会用正确的方式做事。


我有一个动态表,使用Javascript填充。目前我正在寻找使用W3C DOM添加节点,但这些看起来很漂亮,特别是添加所有属性等等。


有没有办法在一堆HTML文本中bla,,或者这件事现在已经皱起了什么?b $ b?



在FAQ小组中使用DynWrite。

< URL:http://jibbering.com/faq/#FAQ4_15>



DynWrite基于innerHTML,这不是修改

表的最佳方法。当用于编写整个表或

a单元格的内容时,它是可以的,但它永远不应该用于表的组件

(tableSection,tableRow,等等。

对于OP:


insertRow和insertCell是将元素添加到

表的非常有效的方法。使用CSS来设置它们的样式可以节省构建表的代码。你可能还认为它适合克隆整行,然后修改单元格的

内容。


< URL: http:// www。 w3.org/TR/DOM-Level-2-HTM...ml#ID-39872903 >

< URL: http://www.w3.org/TR/DOM-Level-2 -HTM ... ml#ID-68927016 >


-

Rob


RobGaécrit:


>

< URL: http://www.w3.org/TR/DOM- Level-2-HTM ... ml#ID-39872903 >

< URL: http://www.w3.org/TR/DOM-Level-2-HTM...ml#ID -68927016 >



IDL定义中的IDL是什么意思?


Hi all,

New to Javascript, and want to learn to do things the RIGHT way.

I have a dynamic table which is populated using Javascript. Currently I
am looking at adding nodes using the W3C DOM, but these seems pretty
long winded, especially adding all the attributes etc.

Is there a way to just blat in a lump of HTML text, or is this frowned
upon now?

Cheers,
Lister

解决方案

li************@hotmail.com said the following on 10/22/2006 5:49 PM:

Hi all,

New to Javascript, and want to learn to do things the RIGHT way.

I have a dynamic table which is populated using Javascript. Currently I
am looking at adding nodes using the W3C DOM, but these seems pretty
long winded, especially adding all the attributes etc.

Is there a way to just blat in a lump of HTML text, or is this frowned
upon now?

Use DynWrite as in the group FAQ.
<URL: http://jibbering.com/faq/#FAQ4_15>

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/


Randy Webb wrote:

li************@hotmail.com said the following on 10/22/2006 5:49 PM:

Hi all,

New to Javascript, and want to learn to do things the RIGHT way.

I have a dynamic table which is populated using Javascript. Currently I
am looking at adding nodes using the W3C DOM, but these seems pretty
long winded, especially adding all the attributes etc.

Is there a way to just blat in a lump of HTML text, or is this frowned
upon now?


Use DynWrite as in the group FAQ.
<URL: http://jibbering.com/faq/#FAQ4_15>

DynWrite is based on innerHTML, which is not the best way to modify
tables. It is OK when used to write an entire table, or the contents of
a cell, but it should never be used for the components of a table
(tableSection, tableRow, etc.).
For the OP:

insertRow and insertCell are quite efficient ways to add elements to a
table. Using CSS to style them can save on table-building code. You
might also find it suitable to clone entire rows, then modify the
content of cells.

<URL: http://www.w3.org/TR/DOM-Level-2-HTM...ml#ID-39872903 >
<URL: http://www.w3.org/TR/DOM-Level-2-HTM...ml#ID-68927016 >

--
Rob


RobG a écrit :

>
<URL: http://www.w3.org/TR/DOM-Level-2-HTM...ml#ID-39872903 >
<URL: http://www.w3.org/TR/DOM-Level-2-HTM...ml#ID-68927016 >

what does mean ''IDL'' in ''IDL definition'' ?


这篇关于动态添加HTML的最佳方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆