Home > Web Front-end > JS Tutorial > jQuery implements RadioButton to do the required verification function method sharing

jQuery implements RadioButton to do the required verification function method sharing

小云云
Release: 2018-01-06 13:40:39
Original
2321 people have browsed it

This article mainly introduces the relevant information on how jQuery implements the required verification function of RadioButton. Friends who need it can refer to it. I hope it can help everyone.

It stands to reason that among the several Radio Buttons on the page, when the page is loaded and initialized, the first one is selected by default, but some special requirements cannot be avoided - all radio buttons are not selected. Only perform required validation when a button is used to trigger an event. For example:


<p class="col-xs-4 col-sm-4 col-md-4"> 
   <p class="radio col-mr-20"> 
     @Html.RadioButtonFor(m => m.Materielcategory, "电子物料", new { data_label = "电子物料", name = "Materielcategory", @readonly = "readonly" }) 
   </p> 
   <p class="radio col-mr-20"> 
     @Html.RadioButtonFor(m => m.Materielcategory, "其他", new { data_label = "其他", name = "Materielcategory", @readonly = "readonly" }) 
   </p> 
</p>
Copy after login

This is how I use JQuery to implement it:


//物料分类做必选校验 
    function TongyiBefore() { 
      var Materielcategory = $(":radio[name=Materielcategory]:checked").val(); 
      if (Materielcategory == null) { 
        layer.alert("请先选择物料分类!", { icon: 7 }); 
        return; 
      } 
         
    }
Copy after login

Note: The Materielcategory variable is not selected In the case of value, it is undefined and can also be considered as null.

Related recommendations:

Summary of common usage of radio button (RadioButton)

RadioButton, input, CheckBox value assignment implementation code in jQuery

Beautiful radio button RadioButton customized based on jquery

The above is the detailed content of jQuery implements RadioButton to do the required verification function method sharing. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template