[英]div disappears when page refreshed
Can't figure out why the below piece of code makes the textfield disappear upon page refresh (when 'No' radio button selected).无法弄清楚为什么下面的代码段会在页面刷新时使文本字段消失(选择“否”单选按钮时)。 Also, after the page is refreshed the default radio button doesn't get selected.此外,页面刷新后,默认单选按钮不会被选中。
Forcing refresh, fixes the problem, though.不过,强制刷新可以解决问题。
Any ideas?有任何想法吗?
<html>
<body>
<div class="editfield">
<div id="field_1">
<label>
<input type="radio" checked="checked" name="radio-1" id="radio-1_id" value="Yes" onclick="document.getElementById('divUrl').style.display='none'">Yes
</label>
<label>
<input type="radio" name="radio-1" id="radio-2_id" value="No" onclick="document.getElementById('divUrl').style.display='block'">No
</label>
</div>
</div>
<div class="editfield" id="divUrl" style="display:none">
<label>Website URL</label>
<input type="text" name="X" id="X_id" value="" />
</div>
</body>
</html>
The page refresh will initiate the page in its' original state. 页面刷新将以其原始状态启动页面。 So the 所以
style="display:none"
will be reactivated on the div and will be hidden and the "Yes" button will also be reenabled 将在div上重新激活并被隐藏,并且“是”按钮也将重新启用
<!DOCTYPE html>
<html lang="en-US">
<body onLoad="document.getElementById('radio-2_id').checked=false; document.getElementById('radio-1_id').checked=true;">
<div class="editfield">
<div id="field_1">
<input type="radio" checked="checked" name="radio-1" id="radio-1_id" value="Yes" onclick="document.getElementById('divUrl').style.display='none'">
<label for='radio-1_id'>
Yes
</label>
<input type="radio" name="radio-1" id="radio-2_id" value="No" onclick="document.getElementById('divUrl').style.display='block'">
<label for='radio-2_id'>
No
</label>
</div>
</div>
<div class="editfield" id="divUrl" style="display:none">
<label>Website URL</label>
<input type="text" name="X" id="X_id" value="" />
</div>
</body>
</html>
just a short recap: 简短回顾一下:
1. on page refresh the div should disappear (all css and js and html that was dynamically set / added is removed) and the selected radio button should be the first (Yes) 1.在页面刷新上,div应该消失(动态设置/添加的所有css和js和html都将被删除),并且选中的单选按钮应该是第一个(是)
2. tested this on all major browser and it works 2.在所有主流浏览器上都对此进行了测试,并且可以正常工作
3. still can't figure out why it wasn't working on Mozilla and IE without the JS refresh 3.仍然不知道为什么没有JS刷新就不能在Mozilla和IE上运行
I moved the radio buttons out of the labels to see if that impacted the refresh in any way and it didn't. 我将单选按钮移出了标签,以查看是否以任何方式影响了刷新,但没有。 Also, I removed an extra </div>
that was in the original code. 另外,我还删除了原始代码中的额外</div>
。
我所做的首先有一个 textarea 插入编号,0 使其只读,然后它不会在刷新时消失,插入 document.getElementById("demo").readOnly=false,true 以启用只读
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.