使用提交按钮进行AJAX实时检查可用性(第2部分) [英] AJAX live checking availability with submit button (part 2)

查看:38
本文介绍了使用提交按钮进行AJAX实时检查可用性(第2部分)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

getUserName.php

getUserName.php

if($num)
{
echo '<img src="images/no.png" width="16" height="16" align="bottom" />';
echo '<div style="color:red">Username was taken. Please type another new     
one.</div>';
}
else
{
echo '<img src="images/yes.png" width="16" height="16" align="bottom" />';
}

  • 比方说我想将消息更改为图像.
    ->已取用户名"更改为no.png
    ->您可以使用它..."更改为yes.png

  • Let's say I want to change the message into image.
    -> "Username taken" change to no.png
    -> "You can use it..." change to yes.png

    test1.php

    test1.php

    $('#addform').submit(function () {
    return $("#userNameCheck").html() == '<div><img src="images/yes.png" width="16" 
    height="16" align="bottom"></div>';
    });
    

  • 在第1部分中,我使用了您可以使用它"消息,请访问test2.php;但是现在,我想使用image(yes.png)代替消息.但是,它失败了.我应该如何修改?

  • In part 1, I was use "You can use it" message go to test2.php; But now, I want to use the image(yes.png) instead of the message. However, it failed. How should I modify?

    推荐答案

    如果img中有ID,请执行以下操作

    If you have ID in the img do something like this

    $("#my_image").attr("src","images/yes.png");
    

    $("#userNameCheck img").attr("src","images/yes.png");
    

    我建议不要在#usernamecheck div中插入HTML,而应将其隐藏或隐藏.这样,您可以在CSS中进行修改,并在需要时显示它,而无需进入JS并查看何时以及是否添加它.

    I would suggest not to inject HTML in the #usernamecheck div but have it as hidden or something. In that way you can tinker with it in CSS and show it when needed without going into the JS and seeing when and if you add it.

    这篇关于使用提交按钮进行AJAX实时检查可用性(第2部分)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆