我正在使用sizzle來選擇DOM的各個部分。JavaScript - 單擊事件時遇到問題
我的代碼如下。問題在於onmouseup事件是在頁面加載時觸發的,而不是用戶與頁面交互時觸發的。
有人可以解釋爲什麼這是請。
謝謝。根據要求
// Effects object
var effects = {
// Display an object
show : function(obj) {
obj.style.display = 'block';
},
// Hide an object
hide : function(obj) {
obj.style.display = 'hide';
},
// Toggle
toggle : function(obj) {
if (obj instanceof Array) {
alert('array');
} else {
alert('single');
}
}
}
// Selector Class
var s = Sizzle;
window.onload = function() {
s('#toggle-content').onmouseup = effects.toggle(s('.hidden-content'));
}
HTML:
<div class="page-content box create-page">
<h1><span class="left">Create Page</span><a class="right" id="toggle-content" href="#">Expand</a></h1>
<div class="hidden-content">
...
</div>
</div>
如果您發佈了一些您想要受此影響的HTML(例如「toggle-content」和「hidden-content」元素),這將有所幫助。 – Pointy 2010-06-28 12:30:59
按要求添加了HTML。 – JasonS 2010-06-28 13:09:48