【发布时间】:2010-11-17 02:26:31
【问题描述】:
我是整个 JavaScript 和 jQuery 编码的新手,但我目前正在做的是我的 HTML:
<a id="tog_table0"
href="javascript:toggle_table('#tog_table0', '#hideable_table0');">show</a>
然后我有一些稍微笨重的代码来调整元素:
function toggle_table(button_id, table_id) {
// Find the elements we need
var table = $(table_id);
var button = $(button_id);
// Toggle the table
table.slideToggle("slow", function () {
if ($(this).is(":hidden"))
{
button.text("show");
} else {
button.text("hide");
}
});
}
我主要想知道是否有一种更简洁的方法来引用源元素,而不必将两个 ID 传递给我的函数?
【问题讨论】:
标签: javascript jquery html events dom