как показать кнопку очистки X в Chrome с типом пароля - PullRequest
0 голосов
/ 02 июня 2018

Мне нужно показать кнопку очистки X в Chrome с типом пароля, который я пытаюсь

input[type="password"] {
  -webkit-appearance: searchfield;
}

input[type="password"]::-webkit-search-cancel-button {
  -webkit-appearance: searchfield-cancel-button;
}
<input type="password" placeholder="enter text here..." />

Ответы [ 3 ]

0 голосов
/ 02 июня 2018

Пожалуйста, проверьте этот код.

/**
 * Clearable text inputs
 */
$(".clearable").each(function() {
  
  var $inp = $(this).find("input:password"),
      $cle = $(this).find(".clearable__clear");

  $inp.on("input", function(){
    $cle.toggle(!!this.value);
  });
  
  $cle.on("touchstart click", function(e) {
    e.preventDefault();
    $inp.val("").trigger("input");
  });
  
});
/* Clearable text inputs */
.clearable{
  position: relative;
  display: inline-block;
}
.clearable input[type=password]{
  padding-right: 24px;
  width: 100%;
  box-sizing: border-box;
}
.clearable__clear{
  display: none;
  position: absolute;
  right:0; top:0;
  padding: 0 8px;
  font-style: normal;
  font-size: 1.2em;
  user-select: none;
  cursor: pointer;
}
.clearable input::-ms-clear {  /* Remove IE default X */
  display: none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<span class="clearable">
  <input type="password" name="" value="" placeholder="">
  <i class="clearable__clear">&times;</i>
</span>
0 голосов
/ 02 июня 2018

Если вы хотите родной / чистый CSS.Это должно работать только в Chrome .

.password {
  -webkit-text-security: disc;
}
<input type="search" class="password" placeholder="enter text here..." />
0 голосов
/ 02 июня 2018

Для input[type='password'] Значок X не поддерживается.Вы должны вручную позаботиться о значке и щелкнуть событие, или вы можете попробовать с этим

.close-icon {
  border: 0 solid transparent;
  background-color: transparent;
  display: inline-block;
  vertical-align: middle;
  outline: 0;
  cursor: pointer;
}

.close-icon:after {
  content: "X";
  display: block;
  width: 15px;
  height: 15px;
  position: relative;
  z-index: 1;
  right: 35px;
  top: 0;
  bottom: 0;
  margin: auto;
  color: black;
  cursor: pointer;
}

.search-box:not(:valid)~.close-icon {
  display: none;
}
<form>
  <input type="password" name="focus" required class="search-box" placeholder="Enter search term" />
  <button class="close-icon" type="reset"></button>
</form>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...