如何用Javascript通过setAttribute去修改Timer是否Enabled?
如题
function onBrowse(){
var timer=document.getElementById("<%=timer1.ClientID %>");
if(timer!=null){
timer.setAttribute(Enabled,true);
}
}
上面的Script并不能把timer1的Enabled设为true
同样, 已经试过timer.setAttribute("enabled",true)
请问各位有什么办法可以做到?
谢谢
[解决办法]
后台:
<asp:Timer ID="timer1" Interval="1" OnTick="LoadAccount" runat="server" Enabled="false" />
<asp:Timer ID="timer2" Interval="1" OnTick="LoadAccount" runat="server" Enabled="true" />
前台:
<span id="myTimer" style="visibility:hidden;display:none;"></span>
<span id="myTimer2" style="visibility:hidden;display:none;"></span>
<script type="text/javascript">
<!--
Sys.Application.initialize();
Sys.Application.add_init(function() {
$create(Sys.UI._Timer, {"enabled":false,"interval":60000,"uniqueID":"myTimer"}, null, null, $get("myTimer"));
});
Sys.Application.add_init(function() {
$create(Sys.UI._Timer, {"enabled":true,"interval":60000,"uniqueID":"myTimer2"}, null, null, $get("myTimer2"));
});
// -->
</script>
可以前台页面load的时候timer的属性就被确定了
javascript里面改变他属性也有种办法就是用<asp:UpdatePanel
<asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager> <input type="button" value="dianji" onclick="javascript:gas();" /> <asp:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate> <asp:Timer ID="myTimer" runat="server" Enabled="true" EnableViewState="true" OnTick="myTimer_Tick1" Interval="10" > </asp:Timer> <asp:Timer ID="myTimer2" runat="server" Enabled="true" EnableViewState="true"> </asp:Timer> <asp:TextBox runat="server" ID="txtasd"></asp:TextBox> <asp:Button runat="server" ID="btnadd" OnClick="btnadd_Click1" Text="asdasdasd" /> </ContentTemplate> </asp:UpdatePanel> <script language="javascript"> function gas() { window.document.getElementById('<%=btnadd.ClientID %>').click(); } </script>