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:
@Html.RadioButtonFor(m => m.Materielcategory, "电子物料", new { data_label = "电子物料", name = "Materielcategory", @readonly = "readonly" })
@Html.RadioButtonFor(m => m.Materielcategory, "其他", new { data_label = "其他", name = "Materielcategory", @readonly = "readonly" })
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; } }
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!