Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/386.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何比较属性值_Javascript_Jquery - Fatal编程技术网

Javascript 如何比较属性值

Javascript 如何比较属性值,javascript,jquery,Javascript,Jquery,可以比较jQuery中的属性值吗 范例 if( $(this).[ attribute value ] == "0") {} else {} 可以使用方法获取属性值: if ($(this).attr("myAttr") == "0") { // "myAttr" value is "0" } else { // "myAttr" value is not "0" } $(this).filter('[attrname=0]').css('background', 'red'

可以比较jQuery中的属性值吗

范例

if( $(this).[ attribute value ] == "0")
{}
else
{}
可以使用方法获取属性值:

if ($(this).attr("myAttr") == "0") {
    // "myAttr" value is "0"
} else {
    // "myAttr" value is not "0"
}
$(this).filter('[attrname=0]').css('background', 'red');
试试这个

if( $(this).attr('myattribute') == "0")    
{
   //Your statements
}    
else    
{
   //Your statements
}

您可以使用
attr
方法获取属性值并进行比较:

if ($(this).attr("attrname") == "0") {
  $(this).css('background', 'red');
}
还可以使用选择器过滤出具有特定属性值的元素:

if ($(this).attr("myAttr") == "0") {
    // "myAttr" value is "0"
} else {
    // "myAttr" value is not "0"
}
$(this).filter('[attrname=0]').css('background', 'red');

谢谢,我忘了保留0的引文:)你应该考虑阅读一个基本的jQuery教程,并复习文档。可能重复的