简体   繁体   English

页面加载后,如何使第一个JS Option出现?

[英]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.

相关问题 当页面使用JavaScript / jQuery加载时,如何获取选择框的第一个选项以自动显示在div中? - How do I get the first option of a select box to display in a div automatically when the page loads with JavaScript/jQuery? JS我该怎么做 <main> 页面加载时重点关注的元素 - JS how do i make a <main> element focused on when the page loads 页面加载后如何使文本输入框光标自动闪烁? - How do I make the text input box cursor blink automatically when the page loads? 在 React JS 中加载页面时如何自动调用 function?(2020 年) - How do I call a function automatically when page loads up in React JS ?(in 2020) 我想在第一次加载时只刷新一次反应页面(功能组件),而不是在任何事件上而是在第一次渲染之后,怎么做? - I want to refresh the react page(functional component) only once when it first loads, not on any event but after first render, how to do that? 页面加载后如何使该正方形出现在指定的X,Y坐标上? - How to make this square appear at specified X,Y coordinates when page loads up? 首次加载页面时的材料 UI 自动完成 select 默认选项 - Material UI Autocomplete select default option when page loads first 首先填充另一个下拉框时,如何显示新的下拉框? - How do I make new drop down boxes appear when another one has been filled in first? 如何使page_action出现在特定页面上? - How do I make page_action appear for a specific page? 向下滚动页面时,如何使导航栏下方出现阴影? - How do I make a shadow appear under the navigation bar when I scroll down the page?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM