我想这样做,但在 asp.net 中。我将如何在 asp.net/后面的代码中编写这个?我已经有了
protected void chkBox_CheckedChanged(object sender, EventArgs e)
{
if (chkBox.Checked){}
else{}
}
和
<asp:Checkbox ID="chkBox" AutoPostBack="True" runat="server"
onCheckedChanged="chkBox_CheckedChanged" />
所以我需要帮助填写其余部分。不过说真的,非常感谢!
更新 2:
此方法有效,但消息/div 显示的时间不够长,无法阅读文本。发现是因为AutoPostBack="true"
。AutoPostBack 完成后如何调用事件(我猜这就是解决问题所需要的)?
function displayDiv(checkbox) {
if (checkbox.checked) {
$("#message1").stop(true, true).show().fadeOut(10000);
$("#message2").hide();
}
else {
$("#message1").stop(true, true).hide();
$("#message2").stop(true, true).show().fadeOut(10000);
}
}
<asp:CheckBox ID="chkNotifyMe" AutoPostBack="True" runat="server" OnCheckedChanged="chkNotifyMe_CheckedChanged" onclick="displayDiv(this)" />
<div id="message1" class="message" ><span>Successfully <small></small></span></div><br />
<div id="message2" class="message" ><span>Removed<small></small></span></div>
(所有的CSS都是一样的)
如此接近,我可以品尝到它:D再次感谢!
最终解决方案 好吧,我将它添加到我的页面以通过 jQuery 调用 AutoPostBack 并在它发布后显示我的消息
function pageLoad() {
<%# autoLaunchJS %>
$("#chkNotifyMe").click(chkNotifyMe_clicked);
}
function chkNotifyMe_clicked(){
var add = $get("chkNotifyMe").checked == true;
PageMethods.WishList(add, <%#ID%>, OnSucceeded, OnFailed);
}
function OnSucceeded(){
refreshStartPage();
if($get("chkNotifyMe").checked){
$("#messageSuccess").stop(true, true).show().fadeOut(5000);
$("#messageRemove").hide();
}
else{
$("#messageSuccess").stop(true, true).hide();
$("#messageRemove").stop(true, true).show().fadeOut(5000);
}
}