【问题标题】:IE does not pick up form processing data in inputs in a jQuery DialogIE 不会在 jQuery 对话框的输入中获取表单处理数据
【发布时间】:2013-12-05 05:29:05
【问题描述】:

我有一个 HTML5 页面,在 jQuery 对话框中包含多个数据输入。我使用输入属性 form=dataInput 将这些数据扫描到表单处理中。它在 Firefox 和 Chrome 中运行良好,但在 IE 中无法正常运行,因为 IE 不支持输入表单属性。 Dialog 小部件的某些内容使输入框元素对表单处理“不可见”。 form 属性为支持 HTML5 的浏览器修复了这个问题,但没有发布的 IE 有这个支持。我试过 $('.ui-dialog').appendTo('form');在 Dialog open: 选项中,但它不能解决问题。有没有办法让 IE 将输入数据从 Dialog 小部件中扫出并进入 $_POST ?

这是一个对话框内的输入框示例

<label><input type="radio" id="unitedStates"  name="country" form="dataInput" value="US">United States</label>

我使用 jQuery Form 插件来执行提交。它有一些选项,例如 beforeSubmit 和 beforeSerialize,但我不太了解文档或提交过程,不知道它们是否可以用来解决这个问题。请具体说明代码或教程。我对此很陌生,以至于我不能很好地遵循一般说明。 ;-)(顺便说一句,IE 有我需要的其他功能支持,只是没有这个。)

这是我的代码以及 Andrew Hagner 的建议和我的修改。对话框有效,但 IE 没有为国家设置值。需要改变什么?

var countrySelected = $("input[type=radio][name=country]").val(); //set earlier by W3C geocoding
var countryChooser = $('#countryChoices').dialog( {       
    autoOpen: false,
    bgiframe: true,
    height: 300,
    width: 850,
    resizable: false,
    draggable: true,
    title: "Click to select another country",
    open: function () {
            $('#regions').tabs(
                {
                event: "mouseover",
                })
        },
    buttons: {
        'Close / continue location input': function ()
                {
                countrySelected = $('input[name=country]:checked').val();
                $(this).dialog('close');
                }
            } 
});
//then later on
getCityFromGeonames3Step(countrySelected);

【问题讨论】:

  • 我建议对输入使用类名,而不是不符合要求的属性,例如 form。然后,您可以让 jQuery 使用您分配的给定类获取所有元素。
  • @cale_b 我​​懂课。我使用 JQuery ajaxForm 插件处理提交,以处理数据、图像、微调器和用户反馈。哪个 ajaxForm 选项可以处理一类数据——或者类似的问题?

标签: forms html jquery-ui internet-explorer


【解决方案1】:

更新:

// Before you enter dialog, assign the element you will
// be grabbing the info from to a variable.
var countrySelectionElement = $("input[type=radio][name=country]").val(); 
var countrySelected = "";

var countryChooser = $('#countryChoices').dialog( {       
autoOpen: false,
bgiframe: true,
height: 300,
width: 850,
resizable: false,
draggable: true,
title: "Click to select another country",
open: function () {
        $('#regions').tabs(
            {
            event: "mouseover",
            })
    },
buttons: {
    'Close / continue location input': function ()
            {
            // Since jQuery won't work in here, use the variable
            // we assigned above to access value.
            countrySelected = countrySelectionElement.val();
            $(this).dialog('close');
            }
        } 
});

//then later on
getCityFromGeonames3Step(countrySelected);

原文:

在打开对话框之前将输入分配给变量:

function OpenDialog()
{
    var input = $("yourinput");

    // Open dialog, use input to work with that element.

    // If you want you can then place the entered data in a hidden field
    // using jQuery, in the same way we are using input here. Then you will
    // be able to post that data back however you like.

}

前几天我遇到了这个问题,我在 jQuery 的 Dialog 网站上找到了这个解决方案。 http://jqueryui.com/demos/dialog/#modal-form

【讨论】:

  • 我相信这个问题是因为对话框被包裹在一个 iframe 中,或者至少这是我在我发布的链接上看到的。
  • 你可能是对的。我查看了对话框文档。我没有得到任何东西,因为 OpenDialog 函数会导致所有选项卡和按钮显示并且对话框不会打开。我在上面的编辑中发布了我的代码。我需要改变什么?有几行被注释掉,因为它们会导致浏览器中的 W3C 地理编码停止工作的第二个问题。
  • 我更仔细地查看了 Dialog 文档,并且 OpenDialog 函数不是必需的,并且在我的代码中,不允许保持 Dialog 框正常工作。修改后的我的代码在上面,并且 IE 没有为输入单选按钮设置变量值。知道我需要改变什么吗?
  • 在您执行的关闭函数中:countrySelected = $('input[name=country]:checked').val(); 您应该执行:countrySelected = countrySelected.val(); 这是因为我所说的将该控件分配给“countrySelected”变量。因此,您可以使用此变量,而不是使用 jQuery 在对话框中找到它(这是行不通的)。你不必像现在这样为这个变量赋值,但我相信你可以。
  • 我更新了答案以显示更改,让我知道它现在是否适合您。
猜你喜欢
  • 2021-07-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-05-11
  • 2021-09-25
  • 1970-01-01
  • 2014-03-02
  • 1970-01-01
相关资源
最近更新 更多