jQuery:如何重写.after(content,content)? [英] jQuery: How do I rewrite .after( content, content )?

查看:79
本文介绍了jQuery:如何重写.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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆