---
title: "jQuery如何判断某个对象有无某个属性"
author: "ifox"
date: "2012-12-04T17:06:24Z"
tags: []
categories: ["Web前端"]
slug: "jquery"
draft: false
lastmod: "2012-12-04T17:06:24Z"
id: 1740976
url: "https://ifox.iteye.com/blog/1740976"
---

var scopeList = '&lt;s:property value="listEntity.strChangeScope"/&gt;';

```
        var scope = scopeList.split("^");
        if (scope.length > 0) {
             for ( var i = 0; i < scope.length; i++)  {
                     if(scope[i]=='01'){                
                             $("#enName").removeAttr("style");        
                     }else if(scope[i]=='02'){                
                             $("#enReAdress").removeAttr("style");
                     }else if(scope[i]=='03'){                
                             $("#enEconomicProperty").removeAttr("style");
                     }else if(scope[i]=='04'){
                             $("#enSupplyScope").removeAttr("style");        
                     }
           }
      }
      if((typeof($("#enName").attr("style"))!="undefined")&&(typeof($("#enReAdress").attr("style"))!="undefined")&&(typeof($("#enEconomicProperty").attr("style"))!="undefined")&&(typeof($("#enSupplyScope").attr("style"))!="undefined")) {
                   $("#message").removeAttr("style");
     }
```

 

 

上面是源码，这段代码的功能是查看变更范围scopt内有没有值，默认所有内容都是隐藏的，如何scopt有值的话就删除掉其相应的style属性(这个属性包含了隐藏)。如果没有变更，也就是scope为空，就显示message里面的内容。主要代码已经用红色字符标记出来了。本来想用jquery来写，只可惜不会，只能用这种方法。