Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/407.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用jQuery包装html的某些部分_Javascript_Jquery - Fatal编程技术网

Javascript 使用jQuery包装html的某些部分

Javascript 使用jQuery包装html的某些部分,javascript,jquery,Javascript,Jquery,我有点像: <div class="the_notice"> <span class="time"> | 3:48pm</span> To <strong>2013-03-16_10-56-33</strong> By <strong>XYX</strong> </div> <div class="the_notice"> <span class="time

我有点像:

<div class="the_notice">
    <span class="time"> | 3:48pm</span>
    To <strong>2013-03-16_10-56-33</strong> By <strong>XYX</strong>
</div>
<div class="the_notice">
    <span class="time"> | 3:48pm</span>
    <div class="wrap">
      To <strong>2013-03-16_10-56-33</strong> By <strong>XYX</strong>
    </div>
</div>

|下午3:48
到2013-03-16_10-56-33XYX
因此,我想要的是:

<div class="the_notice">
    <span class="time"> | 3:48pm</span>
    To <strong>2013-03-16_10-56-33</strong> By <strong>XYX</strong>
</div>
<div class="the_notice">
    <span class="time"> | 3:48pm</span>
    <div class="wrap">
      To <strong>2013-03-16_10-56-33</strong> By <strong>XYX</strong>
    </div>
</div>

|下午3:48
到2013-03-16_10-56-33XYX
如何使用jQuery实现这一点?请帮我一下。

var temp=$('.time');
$('.time').remove();
$(“.the_notice”).contents().wrapAll(“”);
$(“.the_notice”).prepend(临时);

如果内容始终相同,您可以执行以下操作

$('.the_notice').contents().slice(2).wrapAll('<div class="wrap"/>');
$('.the_notice').contents().slice(2.wrapAll)('');

阅读此链接,它可能会帮助您:

我的答案是这样的:

var myTimeIsHere = //calculate your time here;
var x = //calculate x here.;
var y = //calculate y here.;

var newHTML = "<span class='time'>" |+ myTimeIsHere+"</span>"+
              "<div class='wrap'>To <strong> "+x+" </strong>"+
              "by "+y+"</div>";
$(".the_notice").html(newHTML);
var mytimeisher=//在这里计算您的时间;
var x=//在这里计算x。;
var y=//在这里计算y。;
var newHTML=“|+myTimeIsHere+”“+
“到”+x+“”+
“由”+y+”;
$(“.theu notice”).html(newHTML);
带一行(或为清晰起见为3行):

$(“.通知”)
.wrapInner($('')
.prepend($('.the_notice.time').detach());

这不起作用,您正在删除
.time
并包装每个孩子。