首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >帮助找出功能运行不正常的原因

帮助找出功能运行不正常的原因
EN

Stack Overflow用户
提问于 2009-12-08 03:41:39
回答 2查看 105关注 0票数 0

很抱歉再次打扰大家。由于某些原因,当我尝试使用validateusername()运行以下命令时,什么也没有发生。

代码语言:javascript
复制
<script language="javascript">
//<----------------------------------+
//  Developed by Roshan Bhattarai and modified by Harry Rickards
//  Visit http://roshanbh.com.np for the origional version of this script and more.
//  This notice MUST stay intact for legal use
// -------------------------->
function validateusername()
{
    $("#username").blur(function()
    {
        //remove all the class add the messagebox classes and start fading
        $("#msgbox").removeClass().addClass('messagebox').text('Checking...').fadeIn(1000);
        //check the username exists or not from ajax
        $.post("usernamecheck.php",{ username:$(this).val() } ,function(data)
        {
          if(data=='no') //if username not avaiable
          {
            $("#msgbox").fadeTo(200,0.1,function() //start fading the messagebox
            { 
              //add message and change the class of the box and start fading
              $(this).html('This User name Already exists').addClass('messageboxerror').fadeTo(900,1);
            });     
          }
          else
          {
            $("#msgbox").fadeTo(200,0.1,function()  //start fading the messagebox
            { 
              //add message and change the class of the box and start fading
              $(this).html('Username available to register').addClass('messageboxok').fadeTo(900,1);    
            });
          }

        });

    });
}
</script>

这可能是一个简单的错误,但有人能给我指出正确的方向吗?

谢谢

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2009-12-08 04:04:50

代码没有语法错误,但是当您使用事件绑定时,您是否尝试过在页面加载时运行它?我相信你看不到结果,因为相应的输入不会在期望的事件上运行你的函数。

代码语言:javascript
复制
$().ready(function(){
validateusername();
});

此外,使用<script type="text/javascript">language已被弃用。

票数 1
EN

Stack Overflow用户

发布于 2009-12-08 03:58:54

你有没有试过在它运行时显示值?此外,使用Javascript调试器通常也会有所帮助。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/1862405

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档