问题描述
< input name ='button'value ='Submit'type = '提交'/>
< input name ='button'value ='取消'type ='submit'/>
我想使用javascript提交一个全新的值。
this.form ['button'] ='MYVALUE';
this.form.submit();
如何使用全新的按钮参数值提交表单?
如果我点击按钮,表单值包含按钮=提交
或按钮=取消
我想要用按钮='MYVALUE'
。
如何实现此目的。
使用以下示例:
<表单名称= 'myForm的' >
< input type ='submit'name ='subBtn'value ='提交'/>
< input type ='submit'name ='subBtn'value ='取消'/>
< / form>
我用这个:
pre > //截取'onsubmit'函数
document.myForm.onsubmit = function(){
//遍历每个名字='subBtn'
for(i = 0; i< this.subBtn.length; i ++){
//在迭代中重置当前按钮的value属性
this.subBtn [i] .value =My Value;
}
//防止表单提交
返回false;
}
在线演示:
Given a form with the following elements.
<input name='button' value='Submit' type='submit'/>
<input name='button' value='Cancel' type='submit'/>
I want to submit the form using javascript with a completely new value.
this.form['button'] = 'MYVALUE';
this.form.submit();
How do I submit the form with a completely new value for the button parameter?If I click the button the form values contain either button=Submit
OR button=Cancel
I want to submit with button='MYVALUE'
.
How do I achieve this.
With the following example:
<form name='myForm'>
<input type='submit' name='subBtn' value='Submit' />
<input type='submit' name='subBtn' value='Cancel' />
</form>
I used this:
// Intercept the 'onsubmit' function
document.myForm.onsubmit = function(){
// Cycle through each name='subBtn'
for (i = 0; i < this.subBtn.length; i++) {
// Reset value property of current button in iteration
this.subBtn[i].value = "My Value";
}
// Prevent form submission
return false;
}
Demo Online: http://jsbin.com/aqenu
这篇关于使用javascript提交新的值。 (MVC)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!