简体   繁体   English

如何更改元素的值

[英]How to change value of element

Im kinda new to js, trying to change value of "email" input field 我对JS有点陌生,试图更改“电子邮件”输入字段的值

<div class="input-group type-email">
    <div class="input-label  has-placeholder-label">
        <label for="">Your Email Address</label>
    </div>
    <div class="inputs">
        <input name="email" value="" placeholder="" type="email">
    </div>
</div>

I've found a bunch of articles saying how to find an element by id. 我发现了很多文章,说如何通过id查找元素。 How can I do it without id, by type maybe? 没有类型,怎么办没有id? Thank you. 谢谢。

You can use query selectors, for example: 您可以使用查询选择器,例如:

var input = document.querySelector("input[name=email]");
input.value = "Your new value";

More on query selectors here and also here . 有关查询选择器的更多信息,请参见此处此处

Hope it helps! 希望能帮助到你!

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

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