Html 如何根据选定的电台和是否可见来验证文本输入
我有一台收音机。如果我选择Value=1,则显示自定义_281文本字段,如果该字段可见,则在继续之前应该有一些值,如果为空,则显示警报。如果选择的值=2,则隐藏自定义_281,且不强制填写 我似乎无法验证文本字段并显示警报。 这是我的html和jquery。任何帮助都将不胜感激。谢谢Html 如何根据选定的电台和是否可见来验证文本输入,html,jquery,validation,radio-button,Html,Jquery,Validation,Radio Button,我有一台收音机。如果我选择Value=1,则显示自定义_281文本字段,如果该字段可见,则在继续之前应该有一些值,如果为空,则显示警报。如果选择的值=2,则隐藏自定义_281,且不强制填写 我似乎无法验证文本字段并显示警报。 这是我的html和jquery。任何帮助都将不胜感激。谢谢 <div id="editrow-custom_280" class="crm-section editrow_custom_280-section form-item"
<div id="editrow-custom_280" class="crm-section editrow_custom_280-section form-item">
<div class="content">
<input type="radio" id="QFID_1_custom_280" name="custom_280" class="required crm-form-radio" value="1">
<input type="radio" id="QFID_2_custom_280" name="custom_280" class="required crm-form-radio" value="2">
</div>
</div>
<div id="editrow-custom_281" class="crm-section editrow_custom_281-section form-item" novalidate="novalidate" style="display: block;">
<div class="content">
<input id="custom_281" type="text" name="custom_281" maxlength="255" class="crm-form-text" placeholder="Enter Number ">
</div>
</div>
CRM.$(function($) {
showNumber();
function showNumber() {
$('input[name=custom_280]').change(showNumber);
if ($('input[name=custom_280][value=1]').is(':checked')) {
$('div#editrow-custom_281').slideDown('slow').validate({ignore:':not(:visible)'});
}
else {
$('div#editrow-custom_281').slideUp('slow');
}
}
});
CRM.$(功能($){
showNumber();
函数showNumber(){
$('input[name=custom_280]')。更改(showNumber);
如果($('input[name=custom_280][value=1]')是(':checked')){
$('div#editrow-custom_281')。slideDown('slow')。验证({ignore:':not(:visible)});
}
否则{
$('div#editrow-custom_281')。slideUp('slow');
}
}
});
您可以检查单选按钮的选中值是否为1
如果是,则根据显示消息检查输入是否为空
演示代码:
<代码>showNumber();
函数showNumber(){
$('input[name=custom_280]')。更改(showNumber);
如果($('input[name=custom_280][value=1]')是(':checked')){
$('div#editrow-custom_281 input').val('')
$('div#editrow-custom_281')。向下滑动('slideDown')
}否则{
$('div#editrow-custom_281')。slideUp('slow');
}
}
//点击继续btn
$(“#继续”)。在(“单击”,函数(){
//检查检查的valeu是否为1
if($('input[name=custom_280]:checked').val(){
if(!$('div#editrow-custom_281 input').val(){
$('div#editrow-custom_281 input').focus()
console.log(“请填写”)//空
}否则{
控制台日志(“一切正常”)
}
}
})
继续