gpt4 book ai didi

c# - 如何从 C# 调用 Jquery 函数

转载 作者:太空狗 更新时间:2023-10-29 22:22:33 25 4
gpt4 key购买 nike

我想在执行一些代码后淡入淡出一个 div。当使用按钮的 onclientclick 属性时,此 JQuery 函数工作正常。但是,无法从 C# 中调用它。

JS:

function Confirm()
{
$(".saved").fadeIn(500).fadeOut(500);
}

C#:

protected void btnsave_click(object sender, Eventargs e)
{
//some code
upd.update();
ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "Confirm",
"<script type='text/javascript'>Confirm();</script>", true);
}

HTML:

<asp:updatepanel id="upd" runat="server" updatemode="conditional">
<triggers>
<asp:asyncpostbacktrigger controlid="btnsave" eventname="click"/>
</triggers>
<contenttemplate>
<div style="position:relative">
<span class="saved">Record Saved</span>
<asp:gridview....../>
</div>
<asp:button id="btnsave" runat="server" text="save" onclick="btnsave_click"/>
</contenttemplate>
</asp:updatepanel>

CSS:

.saved
{
position:absolute;
background:green;
margin:0 auto;
width:100px;
height:30px;
visibility:hidden;
}

最佳答案

C#

protected void btn_click(object sender, Eventargs e)
{
ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "script", "Confirm();", true);
}

JS:

<script>
function Confirm()
{
$(".saved").fadeIn(500).fadeOut(500);
}
</script>

编辑改进代码

C#

protected void btn_click(object sender, Eventargs e)
{
ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "script", "Confirm();", true);
}

JS:

<script>
$(document).ready(function () {

function Confirm() {
$(".saved").fadeIn(500).fadeOut(500);
};
});
</script>

关于c# - 如何从 C# 调用 Jquery 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22216177/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com