我正在尝试在现有DOM元素之后插入数据。我收到错误“无效的参数”。 - this.parentNode.insertBefore
这在IE8或IE7中不起作用。想法?
Jfiddle示例:http://jsfiddle.net/zJ3Fe/
<a href="#" id="delete_promo">Click</a>
<div id="customer-info" class="span-12">
<form id="UserFormCheckoutForm" method="post" action="/chicagophotographycenter/checkout" accept-charset="utf-8"><div style="display:none;"><input type="hidden" name="_method" value="POST" /></div>
<h2 class="line"><span>Billing/Shipping Address</span></h2>
<div class="padding">
<div id="billing-first-name">
<label>First Name</label><br />
<span><input name="data[User][first_name]" type="text" maxlength="150" value="Fred" id="UserFirstName" /></span>
</div>
<div id="billing-last-name">
<label>Last Name</label><br />
<span><input name="data[User][last_name]" type="text" maxlength="150" value="" id="UserLastName" /></span>
</div><br />
<div id="billing-email">
<label>Email</label><br />
<span><input name="data[User][email]" type="text" maxlength="255" value="" id="UserEmail" /></span><br />
</div>
<div id="billing-phone">
<label>Phone Number</label><br />
<span><input name="data[Customer][phone]" type="text" maxlength="15" value="" id="CustomerPhone" /></span><br />
</div>
<label>Street Address</label><br />
<span><input name="data[Address][0][address]" type="text" maxlength="150" value="" id="Address0Address" /></span><br />
<span><input name="data[Address][0][address2]" type="text" maxlength="150" value="Suite 203" id="Address0Address2" /></span><br />
<div id="billing-city">
<label>City</label><br />
<span><input name="data[Address][0][city]" type="text" maxlength="150" value="" id="Address0City" /></span>
</div>
<div id="billing-state">
<label>State</label><br />
<span><input name="data[Address][0][state]" type="text" maxlength="2" value="IL" id="Address0State" /></span>
</div>
<div id="billing-zip">
<label>Zip</label><br />
<span><input name="data[Address][0][zip]" type="text" maxlength="10" value="" id="Address0Zip" /></span><br />
</div>
</div><!-- end .padding -->
</div><!-- end #customer-info -->
<script type="text/javascript" charset="utf-8">
$('#delete_promo').click(function() {
$('#customer-info').after('<div id="payment">Credit Card</div>');
$('#UserFirstName').val('Test');
return false;
});
</script>
答案 0 :(得分:1)
我不认为这是评论。即使没有它们,我仍然会得到错误。
但是,如果我在</form>
中包含缺少的#customer-info
关闭标记,则问题就会消失。 (验证者是你的朋友!)
奇怪的错误,可能与IE在给出错误嵌套的HTML时所做的奇怪的不一致层次结构技巧有关。
答案 1 :(得分:0)
我刚刚解决了这个问题。这是div的结尾处的疯狂html评论。那些在第4103行搞乱了jquery。'this.nextSibling'作为DispHTMLCommentElement存储在DOM中。出现这是导致问题。我不确定在DOM中保存评论是否标准。似乎Safari,Chrome或FF都不这样做。
after: function() {
if ( this[0] && this[0].parentNode ) {
return this.domManip(arguments, false, function( elem ) {
this.parentNode.insertBefore( elem, this.nextSibling );
});
} else if ( arguments.length ) {
var set = this.pushStack( this, "after", arguments );
set.push.apply( set, jQuery(arguments[0]).toArray() );
return set;
}
},