【问题标题】:Resetting textfield by clicking an image通过单击图像重置文本字段
【发布时间】:2013-05-14 14:17:56
【问题描述】:

我有一个图像,如果单击它,另一个 div 将使用 jquery 将不透明度设置为 0。我还希望如果单击图像,我将重置文本字段。

这是我的代码。

<div id=loginExit>
    <img class='loginEXIT' src='Site_Images/close.png'>
</div>
<div id=loginForm>
    <div class=formC>
        <form name='loginForm' action='loginC.php' method='post'>
            <font face='Verdana' color=#d6d5d0 size=2>
                Email Address: &nbsp;
                <input type=text name='eadd' id=eaddtf style='width:150px;height:20px;border:1px solid #37749e;margin-bottom:5px;'>
               <br>
               Password: &nbsp;
               <input type=password name='pass' style='width:150px;height:20px;border:1px solid #37749e;margin-bottom:5px;'>
               <br>
               <input type=submit value='Login' class='login2' name=Submit style='cursor: pointer;text-decoration:none;font-size:14px; background-color:#46ae18; border:2px solid #58e01b;width:100px;'>
            </font>
        </form>
    </div>
    <div class=clear></div>
</div>


$('.loginEXIT').click(function($event){
    $('#eaddtf').val('');
    $('#login').animate({opacity:0.0},'slow')
    $('#login').animate({left:-100000},'fast')
});

我想重置input#eaddtf 的文本字段。我该怎么办?

【问题讨论】:

  • @Deepu, $event 是事件对象....
  • 仍然无法正常工作。它只是将不透明度设置为 0 然后向左移动.. 但不重置文本字段

标签: jquery html textfield


【解决方案1】:

重置对我有用,但是您忘记将 id 放在登录按钮中

<input type=submit value='Login' class='login2' id="login" name=Submit style='cursor: pointer;text-decoration:none;font-size:14px; background-color:#46ae18; border:2px solid #58e01b;width:100px;'>

【讨论】:

    【解决方案2】:

    试试这个(我不知道你的解决方案为什么不起作用):

    $(document).on('click', '.loginEXIT', function() {
        $('#eaddtf').val('');
        $('#login').animate({opacity:0.0},'slow')
        $('#login').animate({left:-100000},'fast')
    });
    

    【讨论】:

    • 不需要.on(),因为 DOM 不是动态生成的。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-07-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-07
    相关资源
    最近更新 更多