English 中文(简体)
单击时删除类/样式
原标题:Removing class / styles onclick
  • 时间:2012-05-23 21:28:12
  •  标签:
  • jquery
  • css

我有一个点, 一些代码, Im 正在写入, 一旦您点击输入框中的任何一个, 我就需要删除验证错误 。 但是当我使用标准删除列表时, 它们没有想要的效果, 因为它阻止我重新提交 。

你可以看到我的意思:http://jsfiddle.net/5V7Uv/5/

HTML :

<form method="post" name="form1" action="/whatmask_output/">
    <div id="sectioncol">
        <label for="input-whatmask">whatmask</label>
        <input type="text" name="input-whatmask" id="input-whatmask"
        size="22" />
    </div>
    <div id="sectioncol">
        <label for="input-whois">whois</label>
        <input type="text" name="input-whois" id="input-whois" size="22"
        />
    </div>
    <input type="submit" value="submit" "whatmask_input" id="btn-search" align="right"
    />
</form>​

JavaScript :

var hasError = false;
$("form").submit(function (e) {
    var searchReg = /^[a-zA-Z0-9s/.]+$/;
    if ($("#input-whatmask").val() !=    && $("#input-whois").val() !=   ) {
        alert( Enter only one field at a time. );
        return false;
    }
    if (hasError) return false;
    if ($("#input-whatmask").val() !=   ) {
        if (!searchReg.test($("#input-whatmask").val())) {
            $("#input-whatmask").addClass("errorinput").after( <span class="error">Enter a valid value.</span> );
            hasError = true;
            return false;
        }
    } else if ($("#input-whois").val() !=   ) {
        if (!searchReg.test($("#input-whois").val())) {
            $("#input-whois").addClass("errorinput").after( <span class="error">Enter a valid value.</span> );
            hasError = true;
            return false;
        }
    } else {
        alert( No values entered! );
        return false;
    }
});
$("#input-whatmask, #input-whois").click(function () {
    $("#input-whatmask, #input-whois").removeClass("errorinput");
    $("#input-whatmask, #input-whois").removeClass("error");
    $("#input-whatmask, #input-whois").val(  );
    if ($(this).hasClass( errorinput )) {
        $(this).next().remove();
        $(this).removeClass("errorinput");
        hasError = false;
    }
});​
问题回答
if (hasError) return false;

此行看起来像罪犯, 您的 < code> has_ haror 变量在第一次运行( 如果有错误, 当然) 后被设置为真, 并且不会被设置为假 。

尝试在此行之后添加 haseError = 假 :

$("form").submit(function (e) {




相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

jquery ui dialog opens only once

I have a button that opens a dialog when clicked. The dialog displays a div that was hidden After I close the dialog by clicking the X icon, the dialog can t be opened again.

Drop down background url in Safari Issue

selectBox.selectCSS { background: url(/Images/replacementSelectBackground.png) top left no-repeat height:auto; } I have an issue in Safari only where the image is not rendering on top ...

CSS specific for Safari

How do you target specifically safari in css with styles?

Aligning textarea in a form

Ive used the following css code to align my form elements: form { position:relative; } form input { position:absolute; left:11em; } However, the textarea element is not aligned correctly with the ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

CSS problem with page footer

I have defined my page footer in the css file as: #footer { position: absolute; height: 50px; text-align: center; background: #66CCCC; bottom: 0px; left: 0px; width: 100%; height: ...

热门标签