解决方案 »

  1.   

    alert(document.getElementById('btn').currentStyle.width);
    改为:alert(document.getElementById('mytxt').currentStyle.width);
    你的btn都没看到样式
      

  2.   

    可以用JS和className更改mytxt的样式
      

  3.   

    刚才的问题实现了,那我先问一下如果我想修改里面的值怎么做呢  比如下面的代码, (有问题)
    <html>
    <head>
    <title></title>
    <script>
    function get()
    {
    alert(document.getElementById('mytxt').currentStyle.top);  document.getElementById('mytxt').currentStyle.top=5px;//想修改离顶边的距离,但是有问题 alert(document.getElementById('mytxt').currentStyle.top);  }
    </script>
    <style>
    #mytxt{
    border:1px blue solid;
    width:30px;
    top:0px;
    }
    </style>
    </head>
    <body>
    <input type="text" id="mytxt" />
    <input type="button"  onclick="get()" />
    </body>
    </html>
      

  4.   

    读取没有问题了, 这时候我又想了一个问题,如果我想修改里面的值怎么做<html>
    <head>
    <title></title>
    <script>
    function get()
    {
    alert(document.getElementById('mytxt').currentStyle.top);  document.getElementById('mytxt').currentStyle.top=5px;//这里是我的修改,但是有问题 alert(document.getElementById('mytxt').currentStyle.top);  }
    </script>
    <style>
    #mytxt{
    border:1px blue solid;
    width:30px;
    top:0px;
    }
    </style>
    </head>
    <body>
    <input type="text" id="mytxt" />
    <input type="button"  onclick="get()" />
    </body>
    </html>
      

  5.   

    document.getElementById('mytxt').currentStyle.top='5px';
    貌似要引号,单引号还是双引号就不太记得了
      

  6.   

    currentStyle 好像是个只读属性吧。
      

  7.   

    this.className='myclass'把你的属性放在myclass里面!
      

  8.   


    [javascript]获取style标签和外部样式表的样式
    发表于:2008年3月8日 9时47分48秒阅读(6)评论(1) 举报本文链接:http://user.qzone.qq.com/67086071/blog/1204940868[javascript]获取style标签和外部样式表的样式
    function getOuterStyle(selector, attr) 

        var stylesheet = document.styleSheets; 
        var size = stylesheet.length; 
        var sheet = null; 
        var rules = null; 
        var ruleSize = 0; 
        var rule = null; 
        for(var i = 0; i < size; i++) 
        { 
            sheet = stylesheet.item(i); 
            rules = sheet.rules; 
            ruleSize = rules.length; 
            for(var j = 0; j < ruleSize; j++) 
            { 
                rule = rules[j]; 
                if (selector == rule.selectorText) 
                { 
                    return rule.style[attr]; 
                } 
            } 
        } 
        return null;
    } 用这个function就可以了..
    更多JS代码: http://user.qzone.qq.com/67086071
      

  9.   

    获取stylesheet是为了取值,最终还是要改style哦