本帖最后由 tiantian_498 于 2010-02-10 21:04:33 编辑

解决方案 »

  1.   

    试试parseInt<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>test</title>
    </head><body>
      <div id="ab" width="190px"></div>
      <script type="text/javascript">
      alert(parseInt(document.getElementById('ab').getAttribute('width')));
      
      </script>
    </body></html>
      

  2.   

    var width="180px";
    alert(width.replace("px",""));
      

  3.   

    的确用parseInt() 函数就解决了.
    该函数从待转换的字符的第一个字符开始逐个读取字符,直到遇到非数字.然后将读取到的字符转换成数字...例子:<script language="javascript">
    alert(parseInt("180px"));
    </script>
      

  4.   

    个人感觉eval函数比较好用,也可以捕捉异常
      

  5.   

    不知道LZ在什么情况下这样取? parseInt或者截取字符串都可以