如何在javascript中添加一个函数变量到对象字符串

how to append a function variable to an object string in javascript

本文关键字:函数 一个 变量 字符串 对象 javascript 添加      更新时间:2023-09-26
function GenKeyForm(FormNum){
    document.GenNewKey+FormNum.submit();
}

我有多个形式在一个php页面。每个表单都有一个id,每个提交链接都有相同的id,在这个javascript调用GenKeyForm(id)。

我如何添加FormNum对象调用document.GenNewKey.submit?我知道在php中你可以使用。但是我不知道javascript。

PHP的表单名是:

echo '<form action="#" name="GenNewKey'.$num.'" id="GenNewKey'.$num.'" method="POST">

使用点表示法需要对每个属性名使用标识符。如果你想使用字符串,你必须使用方括号符号。

document["GenNewKey" + FormNum].submit();
function GenKeyForm(FormNum){
    document.getElementById("GenNewKey"+FormNum).submit();
}