仅当复选框被选中并且输入被删除且为空时才显示模态

  • 本文关键字:模态 显示 删除 复选框 jquery
  • 更新时间 :
  • 英文 :


由于代码有问题,我感谢您的提前回复。我想做的是:1.当复选框被选中并且手机号码字段不为空时,当客户试图删除该号码时,它应该在焦点向外时发出警报。2.如果选中复选框,并且手机号码字段已经为空,则在焦点离开时不应显示警报。

var textCheckboxChecked = $("input[id$='CheckboxPhone']").is(":checked");
		  $('#profileCell').on('focusout', function() {
		    if (($(this).val().length < 1) && textCheckboxChecked) {
			    alert("test"); //When I delete the existing numer in input, then on focusout, alert works
// That should not show alert on focusout when no number is available at all.
		    }
		  });
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input data-msg-phoneus="This phone number is invalid. Please enter a 10 digit number." autocomplete="off" type="text" class="form-control input-lg js-profileContact valid" value="214-456-6189" name="profileCell" id="profileCell" data-profilecontact="2144566189"
data-profilecontactformat="214-456-6189">
<br><br>
<input autocomplete="off" type="checkbox" id="customerServiceCheckboxPhone" name="customerServiceCheckboxPhone" checked="checked" class="valid">
<label class="checkbox-check" tabindex="0" for="customerServiceCheckboxPhone">Checkbox</label>

$("#profileCell").focusout(function(){
if ($("#customerServiceCheckboxPhone").is(':checked')==true && $("#profileCell").val()=="") { 
alert("mobile Number is mandatory"); 
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input data-msg-phoneus="This phone number is invalid. Please enter a 10 digit number." autocomplete="off" type="text" class="form-control input-lg js-profileContact valid" value="214-456-6189" name="profileCell" id="profileCell" data-profilecontact="2144566189"
data-profilecontactformat="214-456-6189">
<br><br>
<input autocomplete="off" type="checkbox" id="customerServiceCheckboxPhone" name="customerServiceCheckboxPhone" checked="checked" class="valid">
<label class="checkbox-check" tabindex="0" for="customerServiceCheckboxPhone">Checkbox</label>

最新更新