javascript - Input problems in javascript
问题描述
I'm having a problem when i create inputs from a button: https://jsfiddle.net/bg0cv2az/
let liberatePasswordButtonClickHandler = e => {
e.preventDefault()
let idButtonPassword = $(e.currentTarget).closest('#password-changer')
if (idButtonPassword = '#password-changer') {
$(e.currentTarget).html(`<div class="left-column">
<div class="imput-wrapper top">
<div class="imput-title">
<span><strong>New passoword</strong></span>
</div>
<input type="password" placeholder="New passoword here"/>
</div>
<div class="imput-wrapper">
<div class="imput-title">
<span><strong>Re-enter new password</strong></span>
</div>
<input type="password" placeholder="Re-enter new password here"/>
</div>
</div>`)
}
}
$(document).on('click', '#password-changer', liberatePasswordButtonClickHandler)
The inputs doesn't work, anyone know why?
解决方案
It doesn't work as you are setting the entire content within <button>
tag.
You can actually verify this,Click & Press the input. When you are pressed, you can actually type into the input element. But when you release everythign gets cleared. You are not able to get the edit button as onClickListener
of button is active in foreground.
Simple solution is to clear the entire content and then add the html into <div>
...
if (idButtonPassword = '#password-changer') {
$(e.currentTarget).parent().empty() // <- modified line
.html(`<div class="left-column">
<div class="imput-wrapper top">
<div class="imput-title">
...
You can checkout the JSFiddleDemo here
推荐阅读
- javascript - React-day-picker 警告
- azure - Azure 门户添加后不会加载 IP 限制,无法移除限制
- docker - 带有 ceph rbd 的 Kubernetes
- unity3d - Unity3D 动态网格带孔
- c# - 有没有办法指示编译器不要为匿名委托创建内部类?
- c++ - QTcpSocket 发送的数据比想要的多 - Qt/C++
- oracle - 显示 MaxValue 的表单生成器
- signature - 如何在多个 Excel 文件上签署数字签名?
- java - Selenium:无法使用 aShot 库获取完整的页面截图
- ios - 消除视图控制器后firebase功能是否继续运行