jQuery Tools Validator自定义效果-添加和添加去除效果 [英] jQuery Tools Validator Custom Effect - Adding & Removing effects

查看:63
本文介绍了jQuery Tools Validator自定义效果-添加和添加去除效果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经为此工作了很长一段时间,但是很沮丧.我希望有人对我有方向.首先输入代码:

I've worked on this for quite some time now, and am stumped. I'm hoping someone has some direction for me. First the code:

jQuery:

$("#paperwork").bind("onFail", function(e, errors)  {
if (e.originalEvent.type == 'submit') {

    $.each(errors, function()  {
        var input = this.input;
        input.parent().css({color: 'red'}).change(function()  {
            input.parent().css({color: '#444'});
        });
    });
}

});

以及HTML的示例:

<input id="group_1" required="required" type="radio" name="attending" value="Yes"  />Yes
<input id="group_1" type="radio" name="attending" value="No"  />No
<input id="group_1" type="radio" name="attending" value="Not Provided" />Not Provided

<input id="group_1" class="single_text_input" type="text" name="primary_referral"  />
<input id="group_1" class="single_text_input" type="text" name="secondary_referral" />
<span class="group_1">Referrals</span>

有几个部分与上面的非常相似.每个人都有一个对应的<span>(例如,"2","3"等...),我要完成的工作是:

There are several sections that look much like the above. Each with a corresponding <span> (e.g. "2", "3", etc...) What I'm trying to accomplish is this:

运行验证器时,每个输入的.parent()元素变为红色.那是行得通的.当用户更改输入时,.parent()元素将恢复为其原始颜色.那也可以.

When the validator runs, the .parent() element of each input turns red. That is working. When the user makes a change to the input, the .parent() element returns to its original color. That is also working.

除此之外,我想将每个input部分对应的<span>设为红色(文本或背景).然后,当该部分中的所有输入都更改时,相应的<span>返回其原始外观.一个问题(至少对我而言)是,包含输入的div和相应的<span>似乎彼此无关,无论是.parent().child()还是.closest.

In addition to this, I would like to turn each input section's corresponding <span> red (text or background). Then, when all the inputs within that section are changed, the corresponding <span> is returned to its original appearance. One issue (at least for me) is that the div containing the inputs and the corresponding <span> do not seem to be related to each other, whether by .parent(), .child(), or .closest.

推荐答案

只需设置一个与这些div通用的类,以便稍后可以通过该类选择它们.

Just set a class common to those divs, so you can select them later by that class.

这篇关于jQuery Tools Validator自定义效果-添加和添加去除效果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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