[英]Change the value of a text field javascript
Hello I am trying to understand how setting values via the chrome console work and I had success until i tried it on this site: https://www.zalando.de/login/?view=register您好,我正在尝试了解如何通过 chrome 控制台设置值,并且在我在此站点上尝试之前取得了成功: https://www.zalando.de/login/?view=register
It wont let me fill the fields via the chrome console anyone knows why?它不会让我通过 chrome 控制台填写字段,有人知道为什么吗?
var firstname = "Teodor"
document.getElementById("rjqNeP Upa9lO").value = firstname
You are refering to the wrong element.您指的是错误的元素。
Try selecting the input element directly, not the wrapping div:尝试直接选择输入元素,而不是包装 div:
document.getElementById("text-xt7my").value = firstname
At the same time, you were using an ID selector trying to get a class:同时,您正在使用 ID 选择器尝试获取 class:
<div class="rjqNeP Upa9lO">
<input id="text-xt7my" type="text" name="register.firstname" placeholder="Vorname" >
<div>
In case the id is generated dynamically, refer to the class, and traverse down the DOM to find the correct input field:如果 id 是动态生成的,请参考 class,并向下遍历 DOM 以找到正确的输入字段:
document.getElementsByClassName("rjqNeP Upa9lO")[0].childNodes[0].value = firstname
Simply select textbox by its ID = "text-1u2un"只需 select 文本框的 ID = "text-1u2un"
document.getElementById("text-1u2un").value = firstname;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.