为什么这不适用于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>
答案 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