表单提交()不在Firefox中工作但是在chrome中工作?

时间:2014-09-14 00:19:37

标签: javascript

为什么这不适用于Firefox,但正在使用Chrome

<script>
var newValue = 'test';

var f = document.createElement('form');
f.setAttribute('method','GET');
f.setAttribute('action','/test');

var customContext = document.createElement('input');
customContext.setAttribute('type','text');
customContext.setAttribute('name','CUSTOM_CONTEXT');
customContext.value = newValue;

var s = document.createElement('input'); //input element, Submit button
s.setAttribute('type','submit');
s.setAttribute('value','Submit');

f.appendChild(customContext);
f.appendChild(s);

f.submit();
</script>

1 个答案:

答案 0 :(得分:0)

正如@Boaz所指出的那样..

It could be related to the fact that the form is not actually in the DOM. 
Try appending the form to the body and see the difference. 
You can also set the field to be type="hidden" so the addition should not be visible