【问题标题】:CSS select input by classCSS按类选择输入
【发布时间】:2020-04-01 18:22:22
【问题描述】:

我试图找到某种方法来按类选择所有表单输入。

<form action="" class="registerForm">
   <input type="text" name="loginInput" class="registerInputField">
   <input type="email" name="emailInput" class="registerInputField">
   <input type="password" name="passwordInput" class="registerInputField">
   <input type="password" name="confirmPasswordInput" class="registerInputField">
   <input type="submit" value="Register">
   <input type="submit" value="Cancel">
</form>

我试过了:`

input.registerInputField{}
.registerForm > input[type=text]{}
input[type=text].registerInputField{}

我阅读了一些与此相关的主题,但没有用。 我会很高兴向我展示一些可以找到答案的资料或书籍。

【问题讨论】:

  • HTMLElement.getElementsByTagName('input')
  • @AdrianSolarczyk:你没看错,但那是 JavaScript。

标签: html css forms input


【解决方案1】:

您提供的每个示例都有效。如果没有更多的上下文,例如您是否使用 Angular 增加了可能相关的范围,就不可能说出为什么您可能会遇到它不起作用。但这显然有效:

input.registerInputField {
   background-color: purple;
}
<form action="" class="registerForm">
   <input type="text" name="loginInput" class="registerInputField">
   <input type="email" name="emailInput" class="registerInputField">
   <input type="password" name="passwordInput" class="registerInputField">
   <input type="password" name="confirmPasswordInput" class="registerInputField">
   <input type="submit" value="Register">
   <input type="submit" value="Cancel">
</form>

【讨论】:

  • 感谢您的帮助!
  • @Devin Burke Great
猜你喜欢
  • 2013-08-07
  • 2010-11-07
  • 1970-01-01
  • 1970-01-01
  • 2017-11-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多