[英]Unable to update the value of input box using Jquery or Javascript
I am unable to upgrade the value of input box using Javascript or jquery. 我无法使用Javascript或jquery升级输入框的值。 I could see the value is not forced into the dom.
我可以看到价值并没有被迫进入dom。 However, I see the change on UI but not in the elements console.
但是,我在UI上看到了更改,但是在元素控制台中却没有看到。
Manually when I am using the keyboard to input the value updates in console. 当我使用键盘在控制台中输入值更新时手动进行。 However, I am trying to update using javascript the element console is not updated and change is seen in UI.
但是,我正在尝试使用JavaScript进行更新,元素控制台未更新,并且在UI中看到了更改。 Refer the attached image.
请参考所附图片。 Screenshot
屏幕截图
Note: The UI code part cannot be changed by me and is controlled by Third party. 注意:UI代码部分不能由我更改,并且由第三方控制。
UI code
<input type="email" name="email" class="auth0-lock-input" placeholder="yours@example.com" autocomplete="off" autocapitalize="off" aria-label="Email" aria-invalid="true" value="" aria-describedby="auth0-lock-error-msg-email" style="background-image:">
Jquery
$(document).ready(function(){
$('#email').val("test")
});
Javascript
let data = document.getElementsByName('email')
for (elt of data) {
elt.value = "test";
}
Your problem is that you're trying to select the input by id
, but it doesn't have any id
so try with $('[name=email]')
您的问题是您尝试通过
id
选择输入,但是它没有任何id
因此请尝试使用$('[name=email]')
$(document).ready(function(){
$('[name=email]').val("test")
});
Demo 演示版
$(document).ready(function() { $('[name=email]').val("test") console.log($('[name=email]').val()) });
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <input type="email" name="email" class="auth0-lock-input" placeholder="yours@example.com" autocomplete="off" autocapitalize="off" aria-label="Email" aria-invalid="true" value="" aria-describedby="auth0-lock-error-msg-email" style="background-image:">
If you want it in JavaScript you can try with: 如果要使用JavaScript,可以尝试:
let data = document.getElementsByName('email')
data[0].value = "test";
Your JavaScript code works fine! 您的JavaScript代码运行良好!
let data = document.getElementsByName('email') for (elt of data) { elt.value = "test1234"; }
<input type="email" name="email" class="auth0-lock-input" placeholder="yours@example.com" autocomplete="off" autocapitalize="off" aria-label="Email" aria-invalid="true" value="" aria-describedby="auth0-lock-error-msg-email" style="background-image:">
Your jQuery code would work if you gave the element the ID you spcified: 如果您给元素指定了自己的ID,您的jQuery代码就可以使用:
$(document).ready(function(){ $('#email').val("test1234") });
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <input id="email" type="email" name="email" class="auth0-lock-input" placeholder="yours@example.com" autocomplete="off" autocapitalize="off" aria-label="Email" aria-invalid="true" value="" aria-describedby="auth0-lock-error-msg-email" style="background-image:">
add id="email"
on your input because on your jquery you are selecting by # 在您的输入中添加
id="email"
,因为在您的jquery上,您通过#选择
# = 'id'
. = class
# = 'id'
. = class
. = class
$(document).ready(function(){ $('#email').val("test") });
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.0.2/jquery.min.js"></script> <input type="email" id="email" name="email" class="auth0-lock-input" placeholder="yours@example.com" autocomplete="off" autocapitalize="off" aria-label="Email" aria-invalid="true" value="" aria-describedby="auth0-lock-error-msg-email" style="background-image:">
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.