javascript - jquery focusin 事件未触发

标签 javascript jquery html asp.net

我正在验证表单输入,例如单击按钮时说名字。如果为空,我将类更改为

    .ValidateError
{
    border: 3px solid #ff9600;
    background: #ffebe9;
    padding: 4px 4px 5px 4px;
    color: #404040;
}

专注于文本框,我尝试使用 document.ready 上的以下脚本从输入框中删除此类

  $('#divPersonalInfo input').focusin(function () {
        $(this).removeClass().addClass('input w220');
    });
});

这是html代码

    <div id="divPersonalInfo" class="PersonalInfo">

  <h2 id="hPersonal">
    Personal Information
  </h2>

  <div class="FormColumn FloatLeft">
    <label>
      first name*
    </label>
    <br />
    <input maxlength="100" id="txtFirstName" placeholder="First Name" class="input w220 "/>
  </div>

  <div class="FormColumn FloatLeft">
    <label>
      last name*
    </label>
    <br />
    <input maxlength="100" id="txtLastName" placeholder="Last Name" class="input w220"/>
  </div>

  <div class="FormColumn FloatLeft">
    <label>
      email*
    </label>
    <br />
    <input maxlength="100" id="txtPersonalEmailId" placeholder="will be seen when sending your web profile/app to your colleagues" class="input w220"/>
  </div>
</div>

但是该类并未在焦点上被删除

最佳答案

如果你只想删除“ValidateError”,你应该写一个类名

$(this).removeClass("ValidateError");
顺便说一句。使用 jquery 你可以像这样使用你的焦点

$(selector).focus(function) 

关于javascript - jquery focusin 事件未触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18206886/

相关文章:

javascript - 在带有图像映射的 Firefox 和 Opera 中,顶部偏移返回不正确

javascript,从大对象数组返回小对象数组

jquery - 使用 jQuery 将转换附加到现有转换

javascript - magnific-popup 为 YouTube 视频生成 "file not found"错误

javascript - jQuery:为什么选择器会失败?

javascript - 为什么我的 boolean 值返回 'undefined' ?

c# - Microsoft JScript 运行时错误 : 'Sys' is undefined (in mvc3 c# razor)

页面 url 更改的 Javascript 函数

html - 行高元素内的行内 block 元素

javascript - CSS 调整图像大小以适应 div 并响应