Bif*_*ffy 5 html javascript css styles
我试图找出一个特定的元素是否具有内联样式属性:我确定有一个简单的方法来检查它,但我似乎无法找到它.我尝试了很多东西,包括:
var contentWrapper = document.getElementById("contentWrapper");
if(contentWrapper.style.display.toString=="")
alert("Empty");
else
alert("Not Empty");
谢谢您的帮助!
if(contentWrapper.getAttribute("style")){
    if(contentWrapper.getAttribute("style").indexOf("display:") != -1){
        alert("Not Empty");
    } else {
        alert("Empty");
    }
}
if(!contentWrapper.getAttribute("style"))
或者
if(contentWrapper.getAttribute("style")==null || 
   contentWrapper.getAttribute("style")=="")    
以上几行对你有用(任何人都可以选择)。
在第二种解决方案中:
首先检查style attribute元素中是否存在,第二次检查确保它style attribute不作为empty string例如存在<div id="contentWrapper" style="">
完整代码如下:
var contentWrapper = document.getElementById("contentWrapper");
if(contentWrapper.getAttribute("style")==null || contentWrapper.getAttribute("style")=="")
alert("Empty");
else
alert("Not Empty");
http://jsfiddle.net/mastermindw/fjuZW/(第一个解决方案)
http://jsfiddle.net/mastermindw/fjuZW/1/(第二个解决方案)
| 归档时间: | 
 | 
| 查看次数: | 18868 次 | 
| 最近记录: |