javascript from 隐性提交表单

function makeForm(data) {
// 创建一个 form
const tempForm = document.createElement('form')
tempForm.id = 'tempForm'
tempForm.name = 'tempForm'
// 添加到 body 中
document.body.appendChild(tempForm)

// 创建一个用户名输入
const merchantSubId = document.createElement('input')
merchantSubId.type = 'text'
merchantSubId.name = 'merchantSubId'
merchantSubId.value = this.merchantSubId

const BODY = document.createElement('input')
BODY.type = 'text'
BODY.name = 'BODY'
BODY.value = data.BODY

const INFO = document.createElement('input')
INFO.type = 'text'
INFO.name = 'INFO'
INFO.value = data.INFO

const SIGN = document.createElement('input')
SIGN.type = 'text'
SIGN.name = 'SIGN'
SIGN.value = data.SIGN

const CONTENTTYPE = document.createElement('input')
CONTENTTYPE.type = 'text'
CONTENTTYPE.name = 'CONTENTTYPE'
CONTENTTYPE.value = data.CONTENTTYPE

// 将该输入框插入到 form 中
tempForm.appendChild(merchantSubId)
tempForm.appendChild(BODY)
tempForm.appendChild(INFO)
tempForm.appendChild(SIGN)
tempForm.appendChild(CONTENTTYPE)

// form 的提交方式
tempForm.method = 'POST'
// form 提交路径
tempForm.action = data.serverUrl
tempForm.enctype = 'application/x-www-form-urlencoded'

// 对该 form 执行提交
tempForm.submit()
// 删除该 form
document.body.removeChild(tempForm)
}
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容