我有一个无法更改输入值字段名称的表单。 一个这样的字段在 HTML 中如下:
<body>
<form id="f" method="get" action="/code/submit.php">
<input type="text" name="var[list]" id="ixv[list]" value="">
<button type="button" title="Save" onclick="check();">
</form>
</body>
现在在我的 javascript 中,我想访问该输入值。 我试过了,当然它不起作用,因为 [] 看起来 就像 JS 中的数组。
function check() {
var x=var[list].value;
alert(x);
}
问题是变量名中有[]。我怎样才能得到 javascript 中的那个输入字段值?
最佳答案
这个有效:
<input type="text" name="var[list]" id="ixv[list]" value="foo">
alert(document.getElementById('ixv[list]').value);
关于javascript - 如何在输入名称中使用特殊字符访问 javascript 中的表单输入值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16376296/