0

我有2个文本框..

  • 电子邮件

  • 手机号码

我使用链接通过数据库检查 2 个字段JQuery。当我在文本框中输入值时,它应该自动检查该值并显示一个弹出窗口说“已经注册”并获取相关值..

我的代码是

<script type ="text/javascript">
                $('#getCandidate').text('Get Profile') // Sets text for email.
                    .attr('href', '#');

                $("#getCandidate").click(function () {

                    $('#getCandidate').text('Get Profile') 
                    .attr('href', 'GetCandidateDetail?validateEmail=' + $('#Email').val());
                });

                $(document).ready(function () {
                    $('#checkEmail').click(function () {
                        var name = $('#Email').val();
                        var data = 'validateEmail=' + name;
                        $.ajax({
                            type: "GET",
                            url: "ValidateCandidate",
                            data: data,
                            success: function (data) {
                                   alert(data);

                            }
                        });
                        return false;
                    });
                });
          </script>

控制器:

 public ActionResult GetCandidateDetail(string validateEmail, string validateMobile)
    {

        Candidate candidate = null;

        if (!string.IsNullOrEmpty(validateEmail))
        {
            candidate = _userRepository.GetCandidateByEmail(validateEmail);
            if (candidate == null)
               candidate = new Candidate();
        }
        else if (!string.IsNullOrEmpty(validateMobile))
        {
            candidate = _userRepository.GetCandidateByMobileNumber(validateMobile);
            if (candidate == null)
                candidate = new Candidate();
        }
        else
        {
            if (candidate == null)
                candidate = new Candidate();
        }
... 

如何在JQuery不点击链接的情况下自动签到。我尝试了blur function但徒劳无功。

4

1 回答 1

1

您可以 链接或取决于您的trigger需要chekEmailchangeblur

$('#Email').blur(function() {
    $('#checkEmail').trigger('click'); //it will trigger the link when the text losses focus
});

OR

$('#Email').change(function() {
    $('#checkEmail').trigger('click');  //it will trigger the link each time when the text gets changed 
});
于 2013-09-16T13:38:17.590 回答