您好我想自动刷新已检查的页面而不刷新其他页面。我有两个弹出的工作正常,我只是希望单选按钮在检查时工作正常。目前它刷新了10秒后未检查的页面,请有人帮帮我。迅速的回应将受到关注。谢谢
<script type="text/JavaScript">
$(document).ready(function() {
setTimeout("timerefresh();", 10000);
});
function timerefresh()
{
alert(document.getElementById('hdnReload').value + " Before IF");
if (document.getElementById('hdnReload').value == 'MainPage')
{
var SelectedRadioBtn;
var radioButtons = document.getElementsByName("rdbOptions");
for (var x = 0; x < radioButtons.length; x++) {
if (radioButtons[x].checked) {
alert("You checked " + radioButtons[x].id + " which has the value " + radioButtons[x].value);
SelectedRadioBtn = radioButtons[x].value;
//$('input[value ="lstScheduled"]').prop('checked', true);
}
}
setTimeout("location.reload(true);", 10000);
$('input[value ="'+SelectedRadioBtn+'"]').attr('checked', true);
}
else
{
setTimeout("timeRefresh()",10000);
}
}
</script>
答案 0 :(得分:0)
您可以使用setInterval而不是setTimeout,它会减少您的代码。
setInterval(function () {
alert(document.getElementById('hdnReload').value + " Before IF");
if (document.getElementById('hdnReload').value == 'MainPage') {
var SelectedRadioBtn;
var radioButtons = document.getElementsByName("rdbOptions");
for (var x = 0; x < radioButtons.length; x++) {
if (radioButtons[x].checked) {
alert("You checked " + radioButtons[x].id + " which has the value "
radioButtons[x].value);
SelectedRadioBtn = radioButtons[x].value;
//$('input[value ="lstScheduled"]').prop('checked', true);
}
}
setTimeout("location.reload(true);", 10000);
$('input[value ="' + SelectedRadioBtn + '"]').attr('checked', true);
}
}, 10000)