DHTML Tips

1
I'd like to create a table of 100 rows, but for each row, I want to insert some unique data. I could use the createElement() method to create each of the elements in the row, but for a complex row, I might be creating 20 or 30 elements each time. This loses the declarative benefits of DHTML. Instead, I've created a simple templating model. First, I create a table:
<table>
  
<tbody id=TheBody>
    
<tr id=TemplateRow style="display: none">

      
<td id=CellOne></td>
    
</tr>

  
</tbody>
</table>
This row will serve as the template, and is hidden from display by using the display: none cascading style sheets (CSS) property. To create each of the rows, I'm going to use the cloneNode() method, and then insert the cloned row into the table.Here's the table creation code:
<script>
function init() {
  
var
 i, r, b, d;
  b 
=
 TheBody;
  
for (i=0; i<100; i++
) {
    r 
= TemplateRow.cloneNode(true
);
    r.id 
= "NewRow"
;
    r.style.display 
= ""
;
    r.all.CellOne.innerText 
=
 i;
    b.insertBefore(r, 
null
);
  }
}
window.onload 
=
 init;
</script>

2
Preventing a Document From Being Cached

You can prevent a document from being cached by adding the following meta tag to the document.

<META HTTP-EQUIV="Expires" CONTENT="0">

Preventing the document from being cached ensures that a fresh copy of the document will always be retrieved from the site, even during the user's current session, regardless of how the user has set the browser's caching options. This is useful if the content of the document changes frequently.

posted on 2004-08-21 11:23  9yue  阅读(618)  评论(0)    收藏  举报