Dropdown menu and observe(Prototype & script.aculo.us)
上一篇 / 下一篇 2008-10-31 16:00:11 / 个人分类:RoR、Mysql&linux
相关阅读:
- Prototype 学习(概念篇) (googleman2, 2008-9-19)
- Prototype 学习(概念篇) (朱先忠, 2008-10-06)
- Prototype框架参考资料集锦(一) (朱先忠, 2008-10-31)
- Prototype 1.6.0及script.aculo.us 1.8.0特征备忘录 (朱先忠, 2008-10-31)
导入论坛 引用链接 收藏 分享给好友 推荐到圈子 管理 举报
-
引用
删除
stone4102 / 2008-10-31 16:05:47
-
How to add HTML content to the DOM using Prototype
Monday, Oct 13th, 2008 at 1:55 am No Comments See that red beetle in the upper-right hand corner? I create that after the page loads, using Prototype. In fact, all the auxillary content in the header is created after the page loads. It’s not site content and it’s not navigation; it’s just for fun, so why load it before the “real” content, right?!
First, to add content using Prototype, I recommend that you already know or have the content you want to add to the DOM. For example, I wanted to add that red beetle to the DOM using Prototype. I already had it embedded into my document and here’s what the HTML looked like…
<a href="#" onclick="beetles(); return false;">
<img src="/images/beetle1.png" alt="" id="beetle1" border="0" />
</a>To add this content to the DOM after the page has loaded using Prototype, we use the Element constructor, Element.insert, Element.update and document.observe. Here’s what the Prototype code looks like…
document.observe('dom:loaded', function() {
var linkBeetle1 = new Element('a', {
href: '#',
onclick: 'beetles(); return false;'
});
var beetle1 = new Element('img', {
src: '/images/beetle1.png',
id: 'beetle1',
alt: '',
border: '0',
});
linkBeetle1.update(beetle1);
$('header').insert(linkBeetle1);
};
new Element - creates a new HTML element with the provided attributes.
.update - updates/replaces the content of the element with the provided content. In this case, we’re attaching the <img> to the <a href> tag.
.insert - attaches the newly created element into the document to the element you specify.
document.observe(’dom:loaded’… - this will make it so that the content is loaded after the page has been loaded (but before the images are loaded).
And that’s all there is to it!
标题搜索
日历
|
|||||||||
| 日 | 一 | 二 | 三 | 四 | 五 | 六 | |||
| 1 | 2 | 3 | 4 | 5 | 6 | ||||
| 7 | 8 | 9 | 10 | 11 | 12 | 13 | |||
| 14 | 15 | 16 | 17 | 18 | 19 | 20 | |||
| 21 | 22 | 23 | 24 | 25 | 26 | 27 | |||
| 28 | 29 | 30 | 31 | ||||||
数据统计
- 访问量: 2479
- 日志数: 393
- 建立时间: 2008-01-02
- 更新时间: 2008-11-07
