我有具有一个按钮来“添加行”的表。此按钮动态地添加行使用jQuery。它的工作原理通过复制第一...,然后用递增的编号更换所有的ID =“..”。

的问题是,所述行具有一个锐自动完成,其看起来如下:

<td>
    <input type="hidden" name="location_num[0]" value="508318" maxLength="25" style="width:230px" id="location_num[0]"/>
    <input type="textbox" name="location_numDisplayDesc[0]" value="WINNIPEG" maxLength="25" style="width:230px" id="location_numDisplayDesc[0]"/>
    <div id="Container_location_num[0]" style="display:inline;"></div>

    <script type="text/javascript">

        // Initialize autocomplete
        var location_numAC = new YAHOO.widget.AutoComplete(
            "location_numDisplayDesc[0]",
            "Container_location_num[0]",
            locationDataSource,
            acConfig);

        location_numAC.useShadow = true
        location_numAC.useIFrame = true
        location_numAC.dataErrorEvent.subscribe(acErrorFunction);

        // Format results to include the reference number
        location_numAC.formatResult = function(resultItem, query) {
            return resultItem[0];
        };

        // Clear key before request
        location_numAC.dataRequestEvent.subscribe(function fnCallback(e, args) {
        YAHOO.util.Dom.get("location_num[0]").value = ""; });

        // Set key on item select
        location_numAC.itemSelectEvent.subscribe(function(event, args) {
            YAHOO.util.Dom.get("location_num[0]").value = args[2][1];
        });

        // Clear key when description is cleared
        location_numAC.textboxBlurEvent.subscribe(function fnCallback(e, args) {
            if (isEmpty(YAHOO.util.Dom.get("location_numDisplayDesc[0]").value)) {
                YAHOO.util.Dom.get("location_num[0]").value = "";
            } // end if
        });
    </script>
</td>

此代码工作正常Firefox和新创建的自动完成的工作,但在IE(6和7)我正在这意味着没有被成功地创建了location_num_AC错误。我认为,这是因为它没有阅读新创建的输入或DIV,因为它应该。我已经尝试与包裹的JavaScript

$("Container_location_num[0]").ready(function {...});

但似乎并没有工作。没有人有任何其他的想法?

有帮助吗?

解决方案

这是插入到IE中的DOM表单字段不添加到窗体集合正如您所料。

通常可以参考表单域的两种方法之一:

document.forms[0]["myFormName"];
document.forms[0][12];

也就是说,通过它的表单字段名称或由它的索引。但是,当你的添加的表单域在IE您不能按名称引用它,只有通过其索引的DOM。如果你的代码(或任何辅助码)是由它的名字集合中寻找一个表单字段那么你显然有问题。

如果您的唯一关键是名称,你可以通过所有的表单域环路通过索引,找到你要找的内容,但是这显然将是一个线性操作。您也可以通过环发现其表单域的名字,但数字没有索引并更新表单对象自己。

我没有足够的细节知道如何(如果)这是在你的项目中发生的,但它的IE浏览器怪癖这听起来像它可能扮演一个角色,因为你动态添加的领域之一。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top