Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/417.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在浏览器中强制刷新部分页面_Javascript_Jquery_Html - Fatal编程技术网

Javascript 在浏览器中强制刷新部分页面

Javascript 在浏览器中强制刷新部分页面,javascript,jquery,html,Javascript,Jquery,Html,我有以下html: <ul class="scr"> <li class="scr"> <input type="checkbox" class="chkscr"/> <h3>Item Name</h3> <div class="scr">Contents</div> </li> .... </ul> 我的问题是,当

我有以下html:

<ul class="scr">
    <li class="scr">
        <input type="checkbox" class="chkscr"/>
        <h3>Item Name</h3>
        <div class="scr">Contents</div>
    </li>
    ....
</ul>

我的问题是,当我切换最后一个要显示的li元素时,h3元素的内容将消失,直到我单击页面上的其他位置,或者上下滚动页面以使浏览重新绘制窗口的该部分。例如,我在Opera中没有看到这种行为,即使在IE中,这种行为也只发生在最后一个li元素上,所以我很确定这是IE的怪癖,而不是我的代码。我可以通过jquery/javascript强制它重新绘制h3元素吗?

我不能复制。我对您的代码进行了一些重构:

//Set initial state of each scr section
$('input.chkscr').each(function() {
    chkSCR_Click($(this));
});

//Setup click event
$('input.chkscr').click(function() {
    chkSCR_Click($(this));
});

//Toggle corresponding scr section for the checkbox
function chkSCR_Click(ctl) {
    if (ctl.attr('checked')) {
        ctl.siblings('div.scr').stop().show();
    }
    else {
        ctl.siblings('div.scr').stop().hide();
    }
}​

我在这里摆弄了一把小提琴:但我的想法是(我很可能是错的)在你的实际标记中的某个地方有一个borkage。

为什么你有
.chkscr输入作为你的选择器的一部分?我在标记中没有看到任何元素会被选中。@karim79-只是一些旧代码的遗留物。与样本不太相关。input.chkscr将被选中。
//Set initial state of each scr section
$('input.chkscr').each(function() {
    chkSCR_Click($(this));
});

//Setup click event
$('input.chkscr').click(function() {
    chkSCR_Click($(this));
});

//Toggle corresponding scr section for the checkbox
function chkSCR_Click(ctl) {
    if (ctl.attr('checked')) {
        ctl.siblings('div.scr').stop().show();
    }
    else {
        ctl.siblings('div.scr').stop().hide();
    }
}​