[英]How do I make first JS Option appear when the page loads?
I'm using the following script to toggle content or to allow content to appear and disappear upon the click of a radio button. 我使用以下脚本来切换内容或允许内容在单击单选按钮时显示和消失。
<script type="text/javascript">
function showonlyone(thechosenone) {
$('.newboxes').each(function(index) {
if ($(this).attr("id") == thechosenone) {
$(this).show(200);
}
else {
$(this).hide(600);
}
});
}
</script>
If I don't use the following css then every option shows up until one is clicked. 如果我不使用以下CSS,则每个选项都会显示,直到单击一个。
.newboxes {
display: none;
}
The HTML i use for the radio buttons is as follows: 我用于单选按钮的HTML如下:
<input style="vertical-align: middle; margin-top: 4px;" onclick="javascript:showonlyone('newboxes1');" type="radio" name="ProgramChoice" value="Lorem Ipsum" >
This is the information the above information will call to appear and disappear: 这是上述信息将要出现和消失的信息:
<div class="newboxes" id="newboxes1"> Lorem Ipsum </div>
I know that with my css it forces nothing to show upon page load, but without it it will show everything. 我知道,使用CSS时,它不会在页面加载时强制显示任何内容,但是如果没有它,它将显示所有内容。 Does anyone know of a possible way to get it to just show the first option on page load?
有谁知道一种可能的方法,使其仅在页面加载时显示第一个选项?
You can do this without removing your css 您可以在不删除CSS的情况下执行此操作
$(function(){
$('.newboxes').first().show(200);
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.