代码之家  ›  专栏  ›  技术社区  ›  Richard Knop

JavaScript/jQuery中我自己的第一个对象的帮助

  •  0
  • Richard Knop  · 技术社区  · 15 年前

    为了自动化这个过程,我还编写了一个js脚本,它自动向PHP脚本发送AJAX调用,并告诉用户域是否可用,而无需提交表单:

    $(document).ready(function() {
    
        function Domain() {    
            this.name = '';
            this.dotComRegistered = 1;
            this.dotNetRegistered = 1;
            this.dotOrgRegistered = 1;
        }
    
        Domain.prototype.check = function(input) {
            this.name = input;
    
            if (this.name.length >= 3 && this.name.length <= 63) {        
                $.get('check.php', { d : this.name }, function(json) {
    
                    alert(json);
    
                    this.dotComRegistered = $.evalJSON(json).com;
                    this.dotNetRegistered = $.evalJSON(json).net;
                    this.dotOrgRegistered = $.evalJSON(json).org;
    
                });
            }
        }
    
        var domain = new Domain();
    
        var input = ''
    
        $('#domain').keyup(function() {
    
            input = $('#domain').val();
            domain.check(input);
    
        });
    
        $('form').submit(function() {
    
            input = $('#domain').val();
            domain.check(input);
            return false;
    
        });
    
    });
    

    问题是Domain.prototype.check()方法不起作用(我没有收到警报窗口),我不知道问题出在哪里。当我将AJAX调用放在方法之外时,它是有效的,所以这不是问题所在。

    #域是域名的输入字段。

    1 回复  |  直到 15 年前
        1
  •  2
  •   Russ Cam    15 年前

    你和萤火虫有过接触吗?在发出请求的点设置断点,然后从该点开始逐步执行。火车在哪里 dn

    另外,您的域函数处于活动状态是否有特定原因 $(document).ready()