jQuery:如何重写.after(content,content)? [英] jQuery: How do I rewrite .after( content, content )?
问题描述
I've got this form working, but according to my previous question it might not be supported: it isn't in the docs either way -- but the intention is pretty obvious in the code.
$(".section.warranty .warranty_checks :last").after(
$('<div class="little check" />').click( function () {
alert('hi')
} )
, $('<span>OEM</span>') /*Notice this (a second) argument */
);
这是通过简单的.click()
回调插入<div class="little check">
,然后是<span>OEM</span>
的同级项.那我还能怎么写呢?我很难通过链接.after()
和.insertAfter()
的任意组合来构想某些工作吗?
What this does is insert <div class="little check">
with a simple .click()
callback, followed by a sibling of <span>OEM</span>
. How else can I write this then? I'm having difficulty conjuring something working by chaining any combination of .after()
, and .insertAfter()
?
我希望它能起作用,但不能:
I would expect this to work, but it doesn't:
$(".section.warranty .warranty_checks :last").after(
$('<div class="little check" />').click( function () {
alert('hi')
} ).after ( $('<span>OEM</span>') )
);
我也希望它能起作用,但不能:
I would also expect this to work, but it doesn't:
$(".section.warranty .warranty_checks :last").after(
$('<span>OEM</span>').insertAfter(
$('<div class="little check" />').click( function () {
alert('hi')
} )
);
);
-> 请参见我的jsfiddle (示例)
-> Please see my jsfiddle for examples (test case)
推荐答案
这可能是幼稚的答案:
$(".section.warranty .warranty_checks :last").after(
$('<span>OEM</span>')
).after(
$('<div class="little check" />').click( function () {
alert('hi')
}
);
似乎可以正常工作...
Seems to work...
编辑:我在这里错过了重点吗? http://jsfiddle.net/wFx9Z/
EDIT: have I missed the point here? http://jsfiddle.net/wFx9Z/
这篇关于jQuery:如何重写.after(content,content)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!