ie8/ie7之后的jquery不工作
我正在尝试在现有 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>
I'm trying to insert data after an existing DOM element. I'm getting an error "Invalid argument." -- this.parentNode.insertBefore
This is not working in IE8 or IE7. Ideas?
Jfiddle example: 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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我觉得不是评论的问题即使没有它们我仍然会收到错误。
但是,如果我在
#customer-info
中包含缺少的关闭标记,问题就会消失。 (验证器是你的朋友!)
但是奇怪的错误,可能与 IE 在给定错误嵌套的 HTML 时执行的奇怪的不一致层次结构技巧有关。
I don't think it's the comments. I still get the error even without them.
The problem goes away, however, if I include the missing
</form>
close-tag inside#customer-info
. (The validator is your friend!)Strange error though, presumably related to the weird inconsistent-hierarchy tricks IE does when given mis-nested HTML.
我刚刚解决了这个问题。这是 div 末尾的奇怪的 html 注释。这些弄乱了第 4103 行的 jquery。“this.nextSibling”作为 DispHTMLCommentElement 存储在 DOM 中。看来这是造成问题的原因。我不确定在 DOM 中保存注释是否是标准的。 Safari、Chrome 或 FF 似乎都没有这样做。
I just solved this. It's the freaking html comments at the end of the div's. Those were messing up the jquery on line 4103. 'this.nextSibling' was stored in the DOM as DispHTMLCommentElement. Appears this was causing the issues. I'm not sure if saving comments in the DOM is standard or not. Appears that neither Safari, Chrome or FF do that.