简体   繁体   English

如何显示来自文本字段的用户输入

[英]How to display user input from text field

I have a form with a username, password and verification pin inputs. 我有一个包含用户名,密码和验证码输入的表格。 The user enters their username and password and clicks sign in, which will unhide a div that allows them to enter their verification pin. 用户输入用户名和密码,然后单击登录,这将取消隐藏div,从而允许他们输入验证码。 In the hidden div it shows up 'Hello this account is using a verification pin' however I would like to know if there is a way where I can make it say 'hello //username that was entered// this account is using a verification pin'. 在隐藏的div中,它显示“您好,此帐户正在使用验证码”,但是我想知道是否有一种方法可以使它说“您好//输入的用户名//此帐户正在使用验证码”销'。 How would I achieve this? 我将如何实现?

The button that unhides the div 取消隐藏div的按钮

<input class="btn_green_white_innerfade btn_medium" type="button" 
name="submit" id="userLogin" value="Sign in" width="104" height="25" 
border="0" tabindex="5" onclick="showDiv()">

The field where the user enters the username. 用户输入用户名的字段。

<label for="userAccountName">username</label><br>
<input class="textField" type="text" name="username" 
id="steamAccountName" maxlength="64" tabindex="1" value=""><br>&nbsp;<br>

The message that shows up in the hidden div 隐藏的div中显示的消息

<div class="auth_modal_h1">Hello <span 
id="login_twofactorauth_message_entercode_accountname"></span>!</div>
<p>This account is currently using a verification pin.</p>
        </div>

Any help will be appreciated 任何帮助将不胜感激

This should do it: 应该这样做:

var username = document.getElementById("steamAccountName").value
document.getElementById("login_twofactorauth_message_entercode_accountname").innerText = username

Of course it is possible. 当然可以。 You can use the DOM. 您可以使用DOM。 In your showDiv() function you could fetch the entered username with the dom. showDiv() function您可以使用dom获取输入的用户名。 You could do something like: 您可以执行以下操作:

function showDiv() {
    const username = document.getElementById("userLogin");
    const div = getElementById("login_twofactorauth_message_entercode_accountname")
    div.getElementsByTagName("p").innerText = "Hy " + username + ", welcome...";
}

This code should do the trick! 这段代码应该可以解决问题!

Hope this help! 希望有帮助!

This basically means that everything you add to the div is done with jQuery instead of having it mixed which can lead to confusion later. 这基本上意味着您添加到div的所有内容都是使用jQuery完成的,而不是将其混合在一起的,这可能会在以后引起混乱。

  1. Add id="username" to your input. id="username"添加到您的输入中。
  2. Add id="modaldiv" to your hello div id="modaldiv"添加到您的hello div
  3. Remove everything in that div. 删除该div中的所有内容。

     var username = $("#username").val(); var divhtml = "Hello " + username + " <span id='login_twofactorauth_message_entercode_accountname'></span>! $("#modaldiv").html(divhtml); 

The following code will definitely get you started. 以下代码一定会让您入门。 It allows you to get the value that the user has entered in the input box with .value and add content to another div with .innerHTML . 它允许您使用.value获取用户在输入框中输入的值,并使用.innerHTML将内容添加到另一个div中。

 var displayUsername = function() { var username = document.getElementById('username').value if(username != '') { document.getElementById('message').innerHTML = 'Hello '+username+'!' } } 
 <input type="text" name="username" id="username"> <button class="clickMe" onclick="displayUsername()">Click ME!</button> <div id="message"></div> 

I added an id="feedback" to your html: 我在您的html中添加了id =“ feedback”:

<div id="feedback" class="auth_modal_h1" style="display:none;">
    Hello <span id="login_twofactorauth_message_entercode_accountname"></span>!
    <p>This account is currently using a verification pin.</p>
</div>

then, I added this javascript: 然后,我添加了以下javascript:

<script>
    function showDiv() {
        document.getElementById("login_twofactorauth_message_entercode_accountname").innerHTML = document.getElementById("steamAccountName").value;
        document.getElementById("feedback").style.display = 'block';
    }
</script>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何通过文本字段输入用户数据,然后在文本字段下方立即显示? - How to input user data through a text field, then display immediately below the text field? HTML/Javascript - 如何将输入字段中的文本显示为 HTML 代码? - HTML/Javascript - How to display text from input field as HTML code? 如何从数组中获取值以在输入字段中显示为文本 - how to get value from array to display as text in input field 如何在单击按钮时在输入字段中显示文本? - How to display a Text in an input field on a button click? 如何在输入文本字段中显示值? - How to display a value in input text field? 当用户在输入字段中输入数据时,如何从把手页面获取 jquery 中的输入文本值? - How to get the input text value in jquery from handlebar page when user enters data in input field? 仅当用户开始在输入字段中输入时,如何从输入值中删除某些警告文本? - How to remove certain warning text from input value only when user starts typing in the input field? 如何创建一个自动的html输入文本字段,以显示从API提取的值? - How to create an automated html input text field that will display values being fetched from an API? 如何从输入字段的文本中获取子字符串并将其显示到另一个HTML元素 - How to get a substring from the text of an input field and display it to another html element 设置文本输入字段显示值与实际值不同 - Set text input field display value different from actual value
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM