var tmpInput = document.createElement("input");
tmpInput.type = type;
tmpInput.name = name;
if (value != undefined) {
if (value == "") {
tmpInput.value = "";
} else if (value.startsWith("{") && value.endsWith("}")) {
tmpInput.value = encodeURIComponent(value);
}
else {
tmpInput.value = value;
}
} else {
tmpInput.value = "";
}
sfForm.appendChild(tmpInput);
}
用法:
var sfForm = document.createElement("form");
document.body.appendChild(sfForm);
createInput(sfForm, "text", "name", "张三"); // 添加参数
createInput(sfForm, "text", "password", "123456"); // 添加参数
sfForm.method = "post";
//sfForm.target = "id_iframe"; // 如果不想跳转页面就 返回到ifream <iframe id="id_iframe" name="id_iframe" frameborder="0" scrolling="no" marginheight="0" //marginwidth="0" height="8000px" width="100%" style="margin-top:10px;"></iframe>
// sfForm.action = "/api"+url;
sfForm.action = url;
sfForm.hidden = "true";
sfForm.submit();