我得到了两个ID为today
和tomorrow
的div。由于只有其中一个可以显示,我写了一个JavaScript函数在这两个之间切换。jquery在两个视图之间切换
function switchDay(selector) {
if (selector == "tomorrow") {
$("#today").hide();
$("#tomorrow").show();
$("#daySelector").html('<a href="#" onclick="return switchDay(\'today\');">this day</a> | next day');
}
if (selector == "today") {
$("#tomorrow").hide();
$("#today").show();
$("#daySelector").html('this day | <a href="#" onclick="return switchDay(\'tomorrow\');">next day</a>');
}
return false;
}
在我的PHP我附和交换机链路是这样的:
echo '<p id="daySelector">today | <a href="#" onclick="return switchDay(\'tomorrow\');">tomorrow</a></p>';
正如你所看到的,我已经切换的hide()和show()jQuery的功能(以前我是用.style .display函数),并且现在想要还旧的onclick
,而是使用jquery .click()
。虽然,我不知道我将如何改变切换链接。
我怎样才能做到这一点? (最好是,如果它没有让我的脚本变得太大...)
好像你有一些奇怪的逻辑怎么回事......你到底做的是什么呢? – elclanrs
他试图切换显示的div并更新切换视图的链接。 – saml