Javascript 如何比较属性值
可以比较jQuery中的属性值吗 范例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'
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教程,并复习文档。可能重复的