它们之间jQuery选择比较元件的属性(和/或特性) [英] jQuery selector comparing element's attributes (and/or properties) between them

查看:164
本文介绍了它们之间jQuery选择比较元件的属性(和/或特性)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

事情从我的<一开始href=\"http://stackoverflow.com/questions/8369683/javascript-fast-way-to-check-if-form-contents-have-been-changed-before-submissi\">$p$pvious问题:
使用jQuery是有可能的两个属性的选择比较?
我的意思是这样的:

The thing starts from my previous question: Using jQuery is it possible to compare two attributes in a selector? I mean something like:

$('element[atribute1!=attribute2]')

或者,在一个实际的例子:

or, in a practical example:

$('input[name!=id]')

在我的情况,我需要它来获得多少输入字段用来编辑一些HTML表单没有改变,
我试图让这个code的工作:

In my case, I would need it to get how many input fields haven't been changed in an html form used to edit something, I was trying to get this code to work:

if($('input[DefaultValue!=input.value]').lenght==0){...}

对此怎么看?
它应该返回改变字段数(如果我得到0我将停止表单提交,显示一个警告消息并返回,而无需更新)

What about it? It should return the number of changed fields (if i get 0 i will stop form submission, show an alert message and go back without updating)

感谢您的帮助。

推荐答案

没有。如果你通过jQuery的文件,你会看到有没有这样的选择。

No. If you look through jQuery's documentation, you'll see there's no such selector.

还有设置defaultValue 是一个属性,而不是一个属性。

Also defaultValue is a property, not an attribute.

您可以这样做:

var changed = $('input').filter(function() {
    return this.value !== this.defaultValue;
});

这篇关于它们之间jQuery选择比较元件的属性(和/或特性)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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