13

Bootstrap 3.0.0 を使用しており、フォーカスされた入力フォームを使用したい: See here, under Form States.. input focus

私は<input class="form-control" id="focusedInput" type="text" value="This is focused...">これを使用して焦点を合わせましたが、それが得られません。ドキュメントは:focus集中するために使用すると言われていますが、方法がわかりません。

bootstrap.css のコード

.form-control {
  display: block;
  width: 100%;
  height: 34px;
  padding: 6px 12px;
  font-size: 14px;
  line-height: 1.428571429;
  color: #555555;
  vertical-align: middle;
  background-color: #ffffff;
  border: 1px solid #cccccc;
  border-radius: 4px;
  -webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075);
          box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075);
  -webkit-transition: border-color ease-in-out 0.15s, box-shadow ease-in-out 0.15s;
          transition: border-color ease-in-out 0.15s, box-shadow ease-in-out 0.15s;
}

.form-control :focus {
  border-color: #66afe9;
  outline: 0;
  -webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075), 0 0 8px rgba(102, 175, 233, 0.6);
          box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075), 0 0 8px rgba(102, 175, 233, 0.6);
}
4

5 に答える 5

24

input タグ内の autofocus 属性を autofocus に設定することで、目的を達成できます。キーボード入力が入力フィールドにフォーカスされ、光ります。

<input class="form-control" id="focusedInput" type="text" autofocus="autofocus" value="This is focused...">
于 2013-11-16T04:31:26.370 に答える
2
$("#inputID").focus(); // will bring focus
$("#inputID").addClass("focusedInput"); // will give it the bootstrapped focus style
scrollTo("#confirm_deletion"); // actually make browser go to that input

/* scroll to the given element section of the page */
function scrollTo(element)
{
    $('html, body').animate({scrollTop: $(element).offset().top-60}, 500);
}
于 2013-11-18T12:12:19.550 に答える
1

.form-control クラスの :focus セレクターの間のスペースを削除する必要がありました。

.form-control:focus {
  border-color: #66afe9;
  outline: 0;
  -webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075), 0 0 8px rgba(102, 175, 233, 0.6);
          box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075), 0 0 8px rgba(102, 175, 233, 0.6);
}

JSフィドル

于 2014-03-28T04:20:08.567 に答える