Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/408.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript getElementById但用于占位符?_Javascript_Html - Fatal编程技术网

Javascript getElementById但用于占位符?

Javascript getElementById但用于占位符?,javascript,html,Javascript,Html,我正在尝试用javascript自动填充网页中的一些信息 所有字段都有ID,例如: <div id="cc-container" class="field has-float-label"> <input placeholder="ccnumber" id="credit_card_number" maxlength="16" name="credit_card[ovv]" size="16" type="tel" value=""> </div>

我正在尝试用javascript自动填充网页中的一些信息

所有字段都有ID,例如:

<div id="cc-container" class="field has-float-label">
     <input placeholder="ccnumber" id="credit_card_number" maxlength="16" name="credit_card[ovv]" size="16" type="tel" value="">
</div>
但最后一个没有ID:

<div id="cvv-container" class="visa has-float-label">
     <input placeholder="cvv" maxlength="4" name="credit_card[meknk]" size="4" type="tel" value="">
</div>

如何在这种情况下插入所需内容

谢谢

PD:我才刚开始编写代码,所以请不要以为我会理解你对我提出的所有要求

你可以尝试使用任何有效CSS作为带有name属性的选择器:

document.querySelector('[name=“credit_card[meknk]”),value='variable_ccnumber'


试试这个
getElementsByName
Name/Class/querySelector@xmasterdocument.getElementByName(“信用卡[meknk]”)focus();document.getElementById(“信用卡[meknk]”)。value=变量号;像那样?我怎么联系你?@JesusChueca,非常欢迎:)
<div id="cvv-container" class="visa has-float-label">
     <input placeholder="cvv" maxlength="4" name="credit_card[meknk]" size="4" type="tel" value="">
</div>