<input type="text" name="password" id="LAY-user-login-password" placeholder="密码" class="layui-input no-ime" autocomplete="off" onpaste="return false" ondragenter="return false" oncontextmenu="return false;" style="ime-mode:disabled;font-weight: 800">
<input class="password" type="hidden" name="password" id="">
$('#LAY-user-login-password').bind('input', function (e) {
var that = $(this);
var ind = this.selectionStart * 1;
var val = that.val();
function keydel() {
window.onkeydown = function (e) {
if (e.keyCode == 8 && ind == 1 && val.length == 1) {
str = str[0]
} else {
str = val
}
}
}
// 不允许输入中文
for (var i = 0; i < val.length; i++) {
if (val.charCodeAt(i) > 0 && val.charCodeAt(i) < 255) {
$(this).val('')
}
}
if (val.replace(/[\u4e00-\u9fa5]/img, '')) {
$(this).val(val.replace(/[\u4e00-\u9fa5]/img, ''))
}
if (val.length == 0) {
str = ""
}
if (ind == val.lenth) {
str += val[ind - 1]
} else {
if (str.length == val.length) {
str = str
}
else if (str.length > val.length) {
if (val.slice(0, ind) != 'undefined' && val.slice(ind + 1) != 'undefined') {
// 如果是从中间删除(中间字母)
// window.onkeydown = function (e) {
if (keyCode == 8 && ind == 1 && val.length == 1) {
// 一次性删除所有
str = str[0]
} else if (ind == 1 && val.length == 1) {
// 一次性选择所有不按删除键,直接填写
str = val
} else if (str.length - val.length != 1) {
// 删除某一段密码
str = str.slice(0, ind) + str.slice(ind + str.length - val.length)
} else {
// 只删除中间的某一个
str = str.slice(0, ind) + str.slice(ind + 1)
}
} else if (val.slice(0, ind - 1) == 'undefined' && val.slice(ind - 1) != 'undefined') {
// 如果是删除第一个字母
str = str.slice(ind - 1)
} else if (val.slice(0, ind - 1) != 'undefined' && val.slice(ind - 1) == 'undefined') {
// 如果是删除最后一个字母
str = str.slice(0, ind - 1)
} else if (val.slice(0, ind - 1) == 'undefined' && val.slice(ind - 1) == 'undefined') {
// 如果删除所有字母
str = ""
}
} else {
// 加
if (val.slice(0, ind - 1) != 'undefined' && val.slice(ind - 1) != 'undefined') {
// 如果是从中间输入(中间字母)
if (val.length - str.length != 1) {
// 加多位密码
str = str.slice(0, ind - 1) + val.slice(ind - (val.length - str.length))
} else {
// 如果是从中间输入(中间字母)
str = str.slice(0, ind - 1) + val[ind - 1] + str.slice(ind - 1);
}
} else if (val.slice(0, ind - 1) == 'undefined' && val.slice(ind - 1) != 'undefined') {
// 如果是第一个字母前面输入(第一个字母)
str = val[ind - 1] + str.slice(ind - 1);
} else if (val.slice(0, ind - 1) != 'undefined' && val.slice(ind - 1) == 'undefined') {
// 如果是最后输入(最后一个字母)
str = str.slice(0, ind - 1) + val[ind - 1];
} else if (val.slice(0, ind - 1) == 'undefined' && val.slice(ind - 1) == 'undefined') {
// 如果是第一次输入(第一个字母)
str = val[0]
}
}
}
$('.password').val(str)
//input的value值转化为·
$(this).val($(this).val().replace(/./g, '.'))
})
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。