如何在Label Runat Server(C#)中获取Javascript值 [英] How to get Javascript value in Label runat server(C#)

查看:62
本文介绍了如何在Label Runat Server(C#)中获取Javascript值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

海,

我使用JavaScript代码从本地计算机获取当前时间.但是我需要在Label中获取此值,然后将其存储在sql server中.所以我该怎么做请帮助我.

我使用以下脚本.

< script language = " >

// 函数来计算本地时间
// 在其他城市
// 给出了城市的UTC偏移量
函数 calcTime(城市,偏移量){

    // 为当前位置创建日期对象
    d =  日期();
    
    // 转换为毫秒
    // 添加本地时区偏移
    // 获取以毫秒为单位的UTC时间
    utc = d.getTime()+(d.getTimezoneOffset()*  60000 );
    
    // 为其他城市创建新的Date对象
    // 使用提供的偏移量
    nd =  日期(utc +(3600000 * offset));
    
    
    // 以字符串形式返回时间
    返回 " "中的当地时间+ city + "  + nd.toLocaleString();

}

// 获取孟买时间
alert(calcTime(' 孟买''  + 5.5'));

</script> 

解决方案

尝试一下

< asp:标签ID = "  runat = " />

<脚本   类型  ="  > 
     var   = document.getElementById(" <%= Lab.ClientID%>").innerHTML;
    functionX();
</ 脚本 >  



像这样使用Jquery

 


(" )



并将值传递给代码隐藏,您可以查看调用代码JavaScript中的隐藏函数 [ ^ ]


Hai,

i use the javascript code to get current time from local machine. but i need to get this value in Label and then i stored it sql server. so how can i do this please help me..

i use following script.

<script language="JavaScript">

// function to calculate local time
// in a different city
// given the city's UTC offset
function calcTime(city, offset) {

    // create Date object for current location
    d = new Date();
    
    // convert to msec
    // add local time zone offset 
    // get UTC time in msec
    utc = d.getTime() + (d.getTimezoneOffset() * 60000);
    
    // create new Date object for different city
    // using supplied offset
    nd = new Date(utc + (3600000*offset));
    
    
    // return time as a string
    return "The local time in " + city + " is " + nd.toLocaleString();

}

// get Bombay time
alert(calcTime('Bombay', '+5.5'));

</script>

解决方案

Try this

<asp:Label ID="Lab" runat="server" />

<script type="text/javascript">
    var value = document.getElementById("<%= Lab.ClientID %>").innerHTML;
    functionX(value);
</script>



using Jquery like this


("[id


=Lab]")



and to pass the value to codebehind you can have a look on Calling a code-behind function from JavaScript[^]


这篇关于如何在Label Runat Server(C#)中获取Javascript值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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