(每日一题)CSS应用于所有选中的元素

  :checked 选择器用于选择所有选中的复选框、单选按钮和 select 元素的选项。

  注意:要仅检索 select 元素的选定选项,请使用 :selected 选择器。

  句法:

  <pre class="prism line-numbers lang-js" data-lang="JavaScript">$(":checked")</pre>

  下面的示例说明了 jQuery 中的 :checked 选择器:

  示例 1:此示例将 CSS 应用于所有选中的元素(在此示例中为复选框)。

  <pre class="prism line-numbers lang-js" data-lang="JavaScript">`  
  
  
 
     
        jQuery | :checked Selector
    
      
    
    
      
    
    
        $(document).ready(function() {
            $(":checked").wrap("");
        });
    
      
    
        form {
            font-weight: bold;
            font-size: 25px;
            color: green;
        }
    
 
         
  
     
    #  
        jQuery | :checked Selector
      
             
    
        GeeksForGeeks_1
                  
        GeeksForGeeks_2
        GeeksForGeeks_3
     
  
  
  
`</pre>

  输出:

  示例 2:此示例在单选按钮上使用选中的选择器。

  <pre class="prism line-numbers lang-js" data-lang="JavaScript">`  
  
  
 
     
        jQuery | :checked Selector
    
      
    
    
      
    
    
        $(document).ready(function() {
            $(":checked").wrap("");
        });
    
      
    
        form {
            font-weight: bold;
            font-size: 25px;
            color: green;
        }
    
      
 
         
  
  
    #  
        jQuery | :checked Selector
      
             
    
        GeeksForGeeks_1
                  
        GeeksForGeeks_2
                  
        GeeksForGeeks_3
     
  
  
    
`</pre>

  输出:

文章由官网发布,如若转载,请注明出处:https://www.veimoz.com/1960
0 评论
399

发表评论

!