简体   繁体   English

捕获Parsley JS字段错误并更新CSS

[英]grabbing Parsley JS field error and updating CSS

I'm completely new to ParsleyJS and don't really know if what I am doing is a wrong way to approach this. 我是ParsleyJS的新手,真的不知道我在做什么是否是错误的解决方法。 But, as I get an error on a particular field that is being validated by Parsley, I want to update the CSS on the field to outline a solid red border . 但是,当我在Parsley验证的特定字段上遇到错误时, 我想更新该字段上的CSS以勾勒出红色实线边框 I have the following code, where I can extract the CSS, but cant seem to attach a JQuery call to update the CSS on the field. 我有以下代码,可以在其中提取CSS,但是似乎无法附加JQuery调用来更新字段上的CSS。

$('form#logon.parsleyParse').parsley().on('field:error', function() {
    console.log('Validation failed for: ', this.$element);
    var element = '#' + this.$element[0].id;
    console.log(element);
    $(this.$element[0].id).css("border: 1px solid red !important;");
});

Basically, when I console log that element, it prints out the proper CSS element.. But, I can seem to make the call to JQuery to change the CSS.. 基本上,当我在控制台上记录该元素时,它会打印出正确的CSS元素。但是,我似乎可以调用JQuery来更改CSS。

Any ideas on what the best way to do this? 关于最佳方法的任何想法? Or how to do this properly? 或如何正确执行此操作?

Parsley will add error classes for you, so you simply need to specify some CSS rules for those classes. Parsley将为您添加错误类,因此您只需为这些类指定一些CSS规则。

Parsley has many examples, check out how it's done there. 欧芹有很多例子,看看那里是怎么做的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM