[英]How can I take inputs with hidden input box?
I am trying to take an input
when a button
is pressed that is if I press a button
it should focus itself to the input
box. 我试图在按下button
时进行input
,也就是说,如果按下button
它应该将自己聚焦于input
框。 But I don't want that the actual input to be displayed on the screen or rather the actual input
box. 但是我不希望实际输入显示在屏幕上,而是实际input
框。 So far I have tried this code: 到目前为止,我已经尝试了以下代码:
$(document).ready(function() {
let Button = document.createElement('button');
let TxtB = document.createTextNode('Button');
let Btn = document.createElement('button');
let TxtAdd = document.createTextNode('Btn');
let Input = document.createElement('Input');
$(Button).append(TxtB);
$(Btn).append(TxtAdd);
$(Input).attr('type', 'hidden');
$(Button).bind("click", function() {
Input.focus();
})
$(Btn).bind("click", function() {
console.log(Input.value);
})
$(document.body).append(Button);
$(document.body).append(Input);
$(document.body).append(Btn);
})
This code gives a null
value no matter what I enter. 无论我输入什么,此代码都会给出一个null
值。
I think that you want to show the input control but hide the value it contains. 我认为您想显示输入控件,但隐藏它包含的值。 if that is the case then try : 如果是这种情况,请尝试:
$(Input).attr('type', 'password');
instead of : 代替 :
$(Input).attr('type', 'hidden');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.