javascript 如何在asp.net c#中调用jquery函数调用?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19442702/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how to call jquery function call in asp.net c#?
提问by Vivek Parikh
I want to show division for 5 seconds while i do every postback in c#.I am using below function to do that but it doesn't work.
我想在 c# 中执行每个回发时显示 5 秒钟的除法。我使用下面的函数来做到这一点,但它不起作用。
I used this code on page load in c#.
我在 C# 中的页面加载中使用了此代码。
Page.ClientScript.RegisterStartupScript(Page.GetType(), "PostbackClick", "setTimeout(function() { $('#correct').fadeOut(1500); }, 5000)", true);
in aspx page
在aspx页面
<script type='text/javascript' src='Scripts/scripts/jquery.min.js'></script>
<script type="text/javascript">
$(document).ready(function () {
$('#correct').hide();
});
</script>
<img alt="" id="correct" src="Que-img/correct.png" />
回答by Kiarash
use
利用
RegisterClientScriptBlock(Page.GetType(), "PostbackClick", "$(document).ready(function(){
setTimeout(function() { $('#correct').fadeIn(1500); }, 5000)});", true)
Because you have to wait for JQuery.ready before using jquery selectors. RegisterStartupScript actually happens before jquery ready. in my answer your setTimer will executed on jquery ready
因为在使用 jquery 选择器之前必须等待 JQuery.ready。RegisterStartupScript 实际上发生在 jquery 准备好之前。在我的回答中,您的 setTimer 将在准备好 jquery 时执行
回答by Rohan Kumar
You already hiding the imagein document.ready function
您已经将图像隐藏在document.ready function
<script>
$(document).ready(function () {
//$('#correct').hide(); // remove this line or comment
// because fadeOut will work on visible elements
function hideImage() {
setTimeout(function() { $('#correct').fadeOut(1500); }, 5000);
};
});
</script>
In C#
在C# 中
Page.ClientScript.RegisterStartupScript(Page.GetType(),"PostbackClick", "script",
"hideImage();" true);
How to Call Jquery from C#will help you
如何从 C# 调用 Jquery会帮助你
回答by iJade
I guess i got your issue ...Modify your code as below
我想我得到了你的问题......修改你的代码如下
$(document).ready(function () {
$('#correct').hide();
$('#btnId').click(function(){
$('#correct').show();
setTimeout(function() { $('#correct').fadeOut(1500); }, 5000);
});
});
and remove
并删除
Page.ClientScript.RegisterStartupScript(Page.GetType(), "PostbackClick", "setTimeout(function() { $('#correct').fadeOut(1500); }, 5000)", true);
Here is the demo
这是演示