有些时候要对input标签的某些类型进行css样式的控制,例如页面中只对type=“text”或type=“password”的input标签进行样式控制。但是页面中还存在type="checkbox"、type="button"等类型。如果对input进行样式控制,那么所有类型就将执行css代码。

所以我们可以用js来控制

代码如下

<script language="javascript" type="text/javascript">
      var obj = document.getElementsByTagName("input");
      for (var i=0; i<obj.length; i++)
      {
            if (obj[i].type=="text"||obj[i].type=="password"){obj[i].style.width="200px" }
      }
</script>
<input type="text"><br>
<input type="password"><br>
<input type="checkbox">

相关文章:

  • 2022-02-10
  • 2022-12-23
  • 2022-12-23
  • 2022-03-04
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-05-19
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-06-15
  • 2022-12-23
  • 2022-12-23
  • 2021-09-14
相关资源
相似解决方案