【问题标题】:change textbox border style at runtime在运行时更改文本框边框样式
【发布时间】:2013-01-16 13:56:56
【问题描述】:

在运行时更改文本框边框样式:

我试过这个代码

 <script type="text/javascript">
    function validate()
    {
       alert("hello");
       document.getElementById("emailid").border.style="1px solid green";
       document.getElementById('emailid').border.style="1px solid green";
    }
    <script>

    <td>Email:</td><td> <input type="text" name="emailid" id="emailid" value="" onblur="validate();"  maxlength=125 /><br></td>

它向我显示警报框,但文本框的边框没有改变 帮助工作测试代码

【问题讨论】:

    标签: html textbox styles border


    【解决方案1】:

    这样做

    document.getElementById("emailid").style.border = "1px solid green";
    document.getElementById("emailid").style.border = "1px solid green";
    

    而不是

    document.getElementById("emailid").border.style = "1px solid green";
    document.getElementById("emailid").border.style = "1px solid green";
    

    【讨论】:

      【解决方案2】:

      您的结束脚本标签是 &lt;script&gt; 而不是 &lt;/script&gt; - 这可能会影响事情。此外,我强烈建议您获取 JQuery 或其他一些库,因为使用它们可以消除任何跨浏览器的不一致(并使您必须编写的代码更短)。

      【讨论】:

        【解决方案3】:
        please try this code
        
        <script type="text/javascript">
        function validate()
        {
            alert("hello");
           document.getElementById('emailid').style.border="1px solid green";
        }
        </script>
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2013-03-06
          • 2022-10-25
          • 2013-07-23
          • 2023-04-03
          • 1970-01-01
          • 1970-01-01
          • 2014-05-31
          • 2012-11-15
          相关资源
          最近更新 更多