简体   繁体   English

如何访问包含弹出窗口的JavaScript中的表单元素

[英]How do I access the form element in JavaScript which contains popup window

How do I access the input with id="namesignup" in javascript?? 如何在JavaScript中使用id="namesignup"访问输入?

I tried using 我尝试使用

console.log("Result :"+ $$('.popup-signup-email #namesignup'));
document.getElementById(namesignup)

Both are not working.. is there how to i access the data in the input?? 两者都无法正常工作..请问我该如何访问输入中的数据? Please help 请帮忙

<div data-page="signup" class="page no-navbar">
<!-- Begin: Page Content -->
<div class="page-content">
<div class="content-block"> </div>
<div class="content-block">
<p>
<button class="button big"><span>Connect with Facebook</span></button>
</p>
<p>
<button class="button"><span>Connect with Google</span></button>
</p>
<p>
<a href="#" class="button open-popup" data-popup=".popup-signup-email">
<span>Sign Up with Email</span>
</a>
</p>
</div>
</div>
<!-- End: Page Content -->

<!-- Begin: Popup -->
<div class="popup tablet-fullscreen popup-signup-email">
<div class="toolbar">
<div class="toolbar-inner">
<div class="left">
<a href="#" class="link disabled"></a>
</div>
<div class="center">Sign Up</div>
<div class="right">
<a href="#" class="link close-popup">
</a>
</div></div></div>

<div class="container">
<div class="content-block"> </div>
<form name="signup-email" action="#" method="POST" enctype="multipart/form-data">
<div class="list-block no-hairlines">
<ul>
<li>
<div class="item-content">
<div class="item-media"></div>
<div class="item-inner">
<div class="item-input">
<input id="namesignup" type="text" name="name" placeholder="Name" required />
</div>
  1. Make sure you configured the jQuery & check with alias name. 确保已配置jQuery并使用别名进行检查。 By default $ is alias name for jQuery. 默认情况下,$是jQuery的别名。 If properly configured, below code will work, 如果配置正确,下面的代码将起作用,

    $('#namesignup').val() $('#namesignup')。val()

2) If you going with native JavaScript, 2)如果您使用本机JavaScript,

document.getElementById('namesignup').value

Try the code below. 试试下面的代码。 This code looks for change in the namesignup and prints it in the console, 此代码在namesignup查找更改并将其打印在控制台中,

 <div data-page="signup" class="page no-navbar"> <!-- Begin: Page Content --> <div class="page-content"> <div class="content-block"> </div> <div class="content-block"> <p> <button class="button big"><span>Connect with Facebook</span></button> </p> <p> <button class="button"><span>Connect with Google</span></button> </p> <p> <a href="#" class="button open-popup" data-popup=".popup-signup-email"> <span>Sign Up with Email</span> </a> </p> </div> </div> <!-- End: Page Content --> <!-- Begin: Popup --> <div class="popup tablet-fullscreen popup-signup-email"> <div class="toolbar"> <div class="toolbar-inner"> <div class="left"> <a href="#" class="link disabled"></a> </div> <div class="center">Sign Up</div> <div class="right"> <a href="#" class="link close-popup"> </a> </div></div></div> <div class="container"> <div class="content-block"> </div> <form name="signup-email" action="#" method="POST" enctype="multipart/form-data"> <div class="list-block no-hairlines"> <ul> <li> <div class="item-content"> <div class="item-media"></div> <div class="item-inner"> <div class="item-input"> <input id="namesignup" type="text" name="name" placeholder="Name" required /> </div> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script> $("#namesignup").keyup(function(){ console.log($("#namesignup").val()); }); </script> 

As others mentioned in later posts: 正如其他人在以后的文章中提到的:

The document.getElementById('namesignup').value code must be worked but if you have multiple DOM with 'namesignup' Id then this code returns the first element value that has this id. 必须使用document.getElementById('namesignup').value代码,但是如果您有多个带有'namesignup'ID的DOM,则此代码将返回具有此ID的第一个元素值。

If you are using Google Chrome, press F12 -> go to element tab -> search 'namesignup'. 如果您使用的是Google Chrome浏览器,请按F12->转到元素标签->搜索“名称签名”。

Be sure that you have one Element with this id. 确保您有一个具有此ID的元素。

  1. in javascript use document.getElementById("namesignup").value 在javascript中使用document.getElementById(“ namesignup”)。value
  2. in jQuery use $("#namesignup").value() 在jQuery中使用$(“#namesignup”)。value()

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM