在这里与原型(prototype)有点挣扎=我已经创建了这个函数
Event.observe(window, 'load', function() {
if ($$('#test li:first')!=null) {
$('test').down('li').down('a').update('Test');
}
});
基本上,它在找到#test li:first 的页面上有效,但在没有返回的页面上有效
$("test").down("li") is undefined
我只是希望它基本上只有在发现该元素时才起作用,否则不起作用?
编辑:已解决
Event.observe(window, 'load', function() {
try {
if ($$('#test li:first')!=null) {
$('test').down('li').down('a').update('Test');
} }
catch(ex) {
}
});
最佳答案
这并没有真正解决问题;您只是发现了一个很容易修复的错误。
试穿这个尺寸:
$$('#test li:first-child').invoke('update', 'Test');
关于javascript - 原型(prototype)查找元素并仅在找到时执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2352145/