例如输入框 <input type="text" name="mytxt">默认的border式样值能取出来吗? (在自己没定义CSS的情况下)

解决方案 »

  1.   

    ie使用currentStyle,其他标准浏览器使用getComputedStyle,可以获取当前元素应用的样式对象。
      

  2.   

    $(document).ready(function () {
        var mytxt = $("input[name=mytxt]");
        var msg = "边框宽度:" + mytxt.css("border-width");
        msg += "\r\n边框样式:" + mytxt.css("border-style");
        msg += "\r\n边框颜色:" + mytxt.css("border-color");
        alert(msg);
    });
      

  3.   

    <input type="text" name="mytxt" class="mycls">$('.mycls').css({backgroundColor:'#eee'});
    其实,我只想改变输入框的背景色
    可是整个输入框的式样都变了。如何只想改变输入框的背景色,其他式样值不变?   
      

  4.   

    其他值本来就不会变啊。。$(document).ready(function () {
        var mytxt = $("input[name=mytxt]");    mytxt.css("background-color", "#eee"); //用 backgroundColor 貌似不行吧??    var msg = "边框宽度:" + mytxt.css("border-width");
        msg += "\r\n边框样式:" + mytxt.css("border-style");
        msg += "\r\n边框颜色:" + mytxt.css("border-color");
        alert(msg);// 他弹出的值还是跟以前一样吧????
    });
      

  5.   


    <head>
    <script type="text/javascript" src="js/jquery.js"></script>
    <script>
    function autocreate_chkbtn() {
      if (document.forms[0].autocreate.checked) {
        $('.mycls').css({backgroundColor:'#eee'});
      }
      else {
        $('.mycls').css({backgroundColor:'#fff'});    
      }  
    }
    </script>    
    </head><body>
     <form method="POST" action="">
      <input type="text" name="mytxt" class="mycls"><br>
      <input type="text" name="mytxt2"><br> 
      <input type="checkbox" name="autocreate" onClick="autocreate_chkbtn()">変換 
     </form> 
    </body>
      

  6.   


    <head>
    <script type="text/javascript" src="js/jquery.js"></script>
    <script>
    function autocreate_chkbtn() {
      if (document.forms[0].autocreate.checked) {
        $('.mycls').css({backgroundColor:'#eee'});
      }
      else {
        $('.mycls').css({backgroundColor:'#fff'});    
      }  
    }
    </script>    
    </head><body>
     <form method="POST" action="">
      <input type="text" name="mytxt" class="mycls"><br>
      <input type="text" name="mytxt2"><br> 
      <input type="checkbox" name="autocreate" onClick="autocreate_chkbtn()">変換 
     </form> 
    </body>