Example For Using the XML DOM

Here’s an example that creates a link to google:

1. var node = createElements({
2. tag: "a",
3. attributes: {
4. href: "http://www.google.com"
5. },
6. style {
7. textDecoration: "none"
8. },
9. children: [ "Click Here!" ]
10. });
11. document.body.appendChild(node);

And here’s a more complex example that really shows off the nesting power of this javascript function:

1. var node = createElements({
2. tag: "div",
3. attributes: {
4. id: "google_link"
5. },
6. children: [
7. {
8. tag: "a",
9. attributes: {
10. href: "http://www.google.com"
11. },
12. style: {
13. textDecoration: "none",
14. fontWeight: "bold"
15. },
16. children: [
17. {
18. tag: "img",
19. attributes: {
20. src: "logo.gif",
21. alt: "Google!",
22. title: "Google!",
23. border: "0"
24. },
25. style: {
26. width: "200px",
27. height: "200px"
28. }
29. },
30. {
31. tag: "br"
32. },
33. "Click here to go to Google!"
34. ]
35.
36. }
37. ]
38. });
39. document.body.appendChild(node);

The above example creates the following code:

1. < id="google_link">
2. < style="text-decoration: none; font-weight: bold;" href="http://www.google.com">
3. < img style="width: 200px; height: 200px;"
title="Google!" alt="Google!"
src="http://www.google.com/intl/en_ALL/images/logo.gif" border="0">
4. <>
5. Click here to go to Google!
6. < /a>
7. < /div>

Xem chi tiết:
Ở đây

Nhận xét

Bài đăng phổ biến từ blog này

dung lượng RAM lớn nhất mà HĐH cấu trúc 32-bit nhận được

Ký tự viết tắt trong chat & email

Ubuntu LAMP Server