Javascript提交表单未在Firefox和IE中提交

本文关键字:提交 IE Firefox 表单 Javascript | 更新日期: 2023-09-27 17:58:16

我正在用javascript向C#MVC中的控制器提交一个表单,它在chrome中很容易提交,但在Firefox和IE 中则不然

//CSHTML CODE    
<th class="gen2">
   <button type="button" id="buttonClass">Generate</button>
</th>
<td class="money"><input type="checkbox" class="chk" name="checkboxID"    value=@item.WithdrawalID></td>

    //Javascript code
        $("#buttonClass").click(function () {
            getValueUsingClass();
        });
        function getValueUsingClass() {
            var data = "";
            var submitForm = document.createElement('form'); 
   //Creating a form and giving the attributes
            submitForm.name = "formSubmit";
            submitForm.id = "formSubmit";
            submitForm.method = "post";
            submitForm.action = "generatebankfile";
            var chkArray = '['];
            alert(chkArray);
            $(".chk:checked").each(function () {
                chkArray.push($(this).val());
            });
            for (var i = 0; i < chkArray.length; i++) {
                data = data + chkArray'[i'];
                if (i != chkArray.length - 1) {
                    data = data + ',';
                }
            }
            var element = document.createElement("input");
            element.name = "checkboxID";
            element.value = data;
            submitForm.appendChild(element);
            if (chkArray.length > 0) {
                submitForm.submit();
            }
            else {
                alert("Please select at least one of the checkbox");
            }
        }

Javascript提交表单未在Firefox和IE中提交

将表单附加到主体

document.getElementsByTagName('body')[0].appendChild(submitForm);