在asp.net中添加javascript [英] adding javascript in asp.net

查看:78
本文介绍了在asp.net中添加javascript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好

我知道asp.net.i想学习javascript.i想知道我是否可以在asp.net页面添加javascript?如果是,怎么样?我目前正在使用visual studio 2010.Thankyou

解决方案

由于JavaScript主要是客户端技术,因此您不需要任何其他技术,因为您已经在使用ASP .NET,你应该明白,从客户端代码的角度来看,没有ASP.NET这样的东西。换句话说,JavaScrip的添加方式与任何HTML完全相同。这里有很好的描述:

http://www.w3schools.com/js/js_howto。 asp [ ^ ]。



与此同时,ASP.NET为脚本提供了一些额外的便利(这些东西仅仅是为了方便起见而考虑的,这些便利性构建在通常的Web之上操作)。请参阅:

http://msdn.microsoft .com / zh-cn / library / system.web.ui.clientscriptmanager.aspx [ ^ ],

http://msdn.microsoft.com/en-us/library/system.web.ui.clientscriptmanager.registerclientscriptblock.aspx [ ^ ]。



-SA


你可以在标题标签中添加脚本并在正文部分使用它。



查找以下示例



 <   html     xmlns   =  http://www.w3.org/1999/xhtml >  
< head runat = server >
< script type = text / javascript >
function isNumber(evt){
evt =(evt)? evt:window.event;
var charCode =(evt.which)? evt.which:evt.keyCode;
if(charCode> 31&&(charCode < 48 || charCode > 57)){
返回false;
}
返回true;
}

< / script >
< / head >
< body >
< 表格 < span class =code-attribute> id = form1 runat = server >
< div >
< 表格 >
< tr >
< td >
< asp:TextBox ID = TextBox1 runat = server onkeypress = return isNumber(event) > < / asp:TextBox >
< / td >
< / tr >
< / table < span class =code-keyword>>


< / div >
< / form >
< / body >
< / html >


< blockquote>我喜欢像这样注入JavaScript:



 ' < span class =code-comment>创建通用html控件 
Dim scrScript As HtmlGenericControl = HtmlGenericControl( script

' 添加我们的javascript
scrScript。 InnerHtml =< JS>
function


hello
i know asp.net.i wanted to learn javascript.i wanted to know if i can add javascript in asp.net pages?if yes,how? i am currently using visual studio 2010.Thankyou

解决方案

As JavaScript is the predominantly a client-side technology, and you would not need anything else as you are already using ASP.NET, you should understand that there is no such thing as "ASP.NET", from the standpoint of the client-side code. In other words, JavaScrip is added in exact same way as for any HTML. This is well described here:
http://www.w3schools.com/js/js_howto.asp[^].

At the same time, ASP.NET offers some additional conveniences for working with scripts (it's good to think of these things merely as of conveniences, which are build on top of the usual Web operation). Please see:
http://msdn.microsoft.com/en-us/library/system.web.ui.clientscriptmanager.aspx[^],
http://msdn.microsoft.com/en-us/library/system.web.ui.clientscriptmanager.registerclientscriptblock.aspx[^].

—SA


just u can add script in header tag and use this same in body section.

Find the below example

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <script type="text/javascript">
        function isNumber(evt) {
            evt = (evt) ? evt : window.event;
            var charCode = (evt.which) ? evt.which : evt.keyCode;
            if (charCode > 31 && (charCode < 48 || charCode > 57)) {
                return false;
            }
            return true;
        }

</script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <table>
            <tr>
                <td>
                    <asp:TextBox ID="TextBox1" runat="server" onkeypress="return isNumber(event)"></asp:TextBox>
                </td>
            </tr>
        </table>


    </div>
    </form>
</body>
</html>


I like do inject JavaScript like so:

'create a generic html control
Dim scrScript As HtmlGenericControl = New HtmlGenericControl("script")

'add our javascript
scrScript.InnerHtml = <JS>
    (function(


这篇关于在asp.net中添加javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆