0

代码有问题,我提前感谢您的回复。我要做的是: 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>

4

1 回答 1

0

$("#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>

于 2020-03-29T11:30:55.783 回答