Java Script简单程序 [英] Java Script simple program
本文介绍了Java Script简单程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
全部
i知道这是javascript中非常基本的编程,当我尝试在asp.net表单运行时会自动回发
代码:
Hi, All
i know this is very basic prog in javascript, when i try to run at asp.net form it automatically post back
Code:
<form id="form1" runat="server">
<div>
<script type="text/javascript">
function myfunction()
{
document.getElementById("demo").innerHTML="Welcome TO JAVA SCRIPT";
}
</script>
<asp:Button ID="Button1" runat="server" Text="Try IT" OnClientClick="myfunction()" />
<br />
<p id="demo">sample Test</p>
</div>
</form>
当我按下button1它显示欢迎来到JAVA SCRIPT但它隐藏在第二个什么即时通讯在此代码中出现错误...
when i press button1 it show "Welcome TO JAVA SCRIPT" but it hide with in second what i make mistake in this code...
推荐答案
向按钮添加AutoPostBack =false。您还可以添加OnClick =javascript:return void(0);。
如果这样可以解决您的问题,请花点时间接受解决方案,以便其他人可以找到它。
谢谢。
Add AutoPostBack="false" to the button. You might also add OnClick="javascript: return void(0);".
If this solves your problem please take the time to accept the solution so others can find it.
Thank you.
如果你从你的javascript函数返回false ,它会阻止回发。
如果你将你的功能修改为:
Hi,
if you return false from your javascript function, it will prevent the postback.
If you modify your function to:
function myfunction()
{
document.getElementById("demo").innerHTML="Welcome TO JAVA SCRIPT";
return false;
}
并将您的按钮修改为:
and modify your button to:
<asp:Button ID="Button1" runat="server" Text="Try IT" OnClientClick="return myfunction();" />
希望它有所帮助。
Hope it helps.
这篇关于Java Script简单程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文