gpt4 book ai didi

javascript - 当页面回发 ASP.NET 时,时间选择器 javascript 停止工作

转载 作者:行者123 更新时间:2023-12-03 07:08:55 26 4
gpt4 key购买 nike

我的 page.aspx 中有一个更新面板,在更新面板内我有带有引导时间选择器的文本框,我展示了一个示例:

      <asp:UpdatePanel runat="server" id="upd1">
<ContentTemplate>
<div class="form-group">
<div class="row col-md-12 col-md-offset-0">
<label class="control-label">Monday</label>
</div>
</div>

<div class="form-group col-md-3">
<div class="input-group bootstrap-timepicker timepicker input-sm">
<asp:TextBox runat="server" ID="txtFecIni_1" class="form-control input-small "></asp:TextBox>
<span class="input-group-addon "><i class="fa fa-clock-o"></i></span>
</div>
</div>

<div class="form-group col-md-3">
<div class="input-group bootstrap-timepicker timepicker input-sm">
<asp:TextBox runat="server" ID="txtFecFin_1" class="form-control input-small "></asp:TextBox>
<span class="input-group-addon "><i class="fa fa-clock-o"></i></span>
</div>
</div>

</ContentTemplate>
</asp:UpdatePanel>

根据</ form>在我的页面中,我添加了以下 JavaScript 代码:

       <script type="text/javascript">
window.onload = function () {
$('#txtFecIni_1').timepicker({
minuteStep: 30,
defaultTime: false,
showMeridian: false
});

$('#txtFecFin_1').timepicker({
minuteStep: 30,
defaultTime: false,
showMeridian: false
});
}

</script>

<script src="js/jquery-2.2.2.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/bootstrap-timepicker.js"></script>

时间选择器正常工作,直到对象被抛出自动回发。我该如何解决这个问题?谢谢。

最佳答案

我这样解决我的问题:

我将window.onload = function ()更改为function pageLoad()像这样:

之前:

     <script type="text/javascript">
window.onload = function () {
$('#txtFecIni_1').timepicker({
minuteStep: 30,
defaultTime: false,
showMeridian: false
});

$('#txtFecFin_1').timepicker({
minuteStep: 30,
defaultTime: false,
showMeridian: false
});
}

</script>

之后:

 <script type="text/javascript">
function pageLoad() {
$('#txtFecIni_1').timepicker({
minuteStep: 30,
defaultTime: false,
showMeridian: false
});

$('#txtFecFin_1').timepicker({
minuteStep: 30,
defaultTime: false,
showMeridian: false
});
}

</script>

我读到每次回发都会调用页面加载。希望这对某人有帮助

关于javascript - 当页面回发 ASP.NET 时,时间选择器 javascript 停止工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36691565/

26 4 0