1

当我尝试通过单击按钮 IE8 将元素添加到 div 时,不要添加它,直到我第二次按下它。然后它添加了两个新元素。这是代码:

$(options.addButton).click(function(event) {
    var prototype = $(options.prototypeContainer).attr('data-prototype');
    event.preventDefault();
    var fileField = $(prototype.replace(/__name__/g, fieldCount));
    fieldCount++;
    $(options.uploadingImagesWrapper).append(fileField);
    //fileField.slideDown();
    return false;
});

容器的标记如下所示:

<div id="uploading-component-images">
    <!-- here I inserts new elements -->
</div>

<!-- the button the triggers insertion function -->
<a class="btn" href="#" id="add-another-image">{{'label.component.add_image_field'|trans }}</a>

单个元素标记如下所示:

<div class="image-file-field">
    <input type="file" name="{{ full_name }}[file]" id="{{ id }}" />
    <button type="button" class="offset0_5 remove-image btn btn-mini">
       <span class="icon-remove"></span>
    </button>
</div>

这是一个屏幕截图-也许有了它会更容易理解。http://joxi.ru/RFBeUtg5CbBaNyCgm14 jquery的版本是1.9.1

4

2 回答 2

1

我有一个类似的问题。尝试以下步骤(无特定顺序):

  1. 放入event.stopPropagation()event.preventDefault()

  2. 改用 html() (或尝试其他变体,例如insertAfter())

  3. 使用$('body').append(...)然后使用 element.offset 以正确的高度和左侧定位它。最后一个对我有用。这是一种痛苦,但 IE8 也是如此。

这是我的代码(我正在使用事件对象来获取偏移量,您可以使用 jQuery 获得相同的行为offset()):

var overflow = $('#overflowContainer');
var windowScrollTop = $(window).scrollTop(); // if window scrolled then need to minus    this from the height so that menu stays in correct place
var target = $($event.currentTarget);
var offset = target.offset();
var dd_top = ((offset.top + target.outerHeight()) - windowScrollTop);
$('body').append(overflow); // must append it to the body for IE to work                        
var left = target.offset().left;
overflow.css({                            
   "top": dd_top + "px",
    "position": "fixed", 
    "left": left // right-aligned with right border of overflow container
});
于 2013-10-16T10:19:38.503 回答
0

将其删除event.preventDefault();或移动到附加句子下方。

于 2013-10-16T09:03:13.697 回答