gpt4 book ai didi

javascript - 在 runat=server 控件上运行脚本

转载 作者:行者123 更新时间:2023-11-29 21:41:52 25 4
gpt4 key购买 nike

如何在具有 runat=server 属性的控件上运行脚本?

删除 runat=server 使脚本运行顺利,但我将无法访问控件。

这是脚本。有什么想法吗?

<input runat="server" type="text" id="txthSchedTime" readonly="true" class="asclock" style="width:100px; background-color:lightyellow" onclick="setTimePicker();" />
<script>
$("#txthSchedTime").AnyTime_picker(
{
format: "%h:%i %p", labelTitle: "Schedule Time",
labelHour: "Hour", labelMinute: "Minutes"
});
</script>

谢谢

最佳答案

您可以像这样从代码后面调用该函数:

你的表单.aspx.cs:

    protected void txthSchedTimeEvent(....)
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "myScript", "myFunction();", true);
}

你的表单.aspx

        <html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>My Page</title>
<script type="text/javascript">
function myFunction(){
$("#txthSchedTime").AnyTime_picker(
{
format: "%h:%i %p", labelTitle: "Schedule Time",
labelHour: "Hour", labelMinute: "Minutes"
});
}
</script>
</head>
<body>
<form id="form2" runat="server">
<table>
<tr> <td>
<asp:TextBox ID="txthSchedTime" runat="server"
style="width:100px; background-color:lightyellow">
</asp:TextBox>
</td> </tr>
</table>
</form>
</body>
</html>

关于javascript - 在 runat=server 控件上运行脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32517150/

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