jQuery show car_orig if $(this).attr(.class)==“car” [英] jQuery show car_orig if $(this).attr(.class)=="car"

查看:350
本文介绍了jQuery show car_orig if $(this).attr(.class)==“car”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 $($)的 li.box li.car this)其中包含修改的值,然后我有包含原始列表的 box_orig car_orig ...



如何替换 $(this)的数据(html数据,li的内容)与原始列表,因此如果 $(this)包含 li.box ,那么我需要替换为 box_orig 的资料



编辑:

  var list = $(ul#list); 

var box_orig = list.children('。box');
var car_orig = list.children ('。car');

$(this)

  $('#list li')。each(function(){
if($ .inArray .attr('class'),show)== 0){
console.log($(this)); // - >返回li.box / car或任何列表
}
});

重新编辑:
/ em>



我意识到替换数据会打断任何东西,所以替换掉了问题,只显示car / box_orig,而不是li.car/box

  $('#list li')。each(
function(){
// alert ($ .inArray($(this).attr('class'),show));
if($ .inArray($(this).attr('class'),show)== 0)
{
if($(this).attr('class')=='box')
{
- > show box_orig,其中包含带信息的lis BUT NOT REPLACE THE DATA,只是显示box_orig而不是$(this)= li.box
}
if($(this).attr('class')=='car')
{
- > show car_orig,其中包含具有信息的lis,但不要替换数据,只显示box_orig而不是$(this)= li.car
}
控制台。 log($(this));
}

html:

  jQuery(li.car)result ... rifting(line 703)
jQuery(li.car)result ... rifting(line 703)
jQuery (行703)
jQuery(li.car)result ... rifting(line 703)
jQuery(li.car)result ... rifting(line 703) )
jQuery(li.car)result ... rifting(line 703)
jQuery(li.car)result ... rifting(line 703)
jQuery(li.car)result ... rifting(line 703)

,每个li.car包含数据(img和文本) / p>
var list = $(ul#list);

var box_orig = list.children('。box');
var car_orig = list.children('。car');

...
$('#list li')。每个(
function(){
//alert($.inArray($)this) .attr('class'),show));
if($ .inArray($(this).attr('class'),show)== 0)
{
if ($(this).attr('class')=='box')
{
list.append(box_orig);
}
if attr('class')=='car')
{
list.append(car_orig);
}
}
...


I have li.box, li.car which are inside a $(this) which contain modified values and then I have box_orig, car_orig containing the original lists...

how can I replace $(this)'s data (html data, the li's content) with the original list, so if $(this) contains li.box then I need to replace it with box_orig's data

Edit:

var list              =   $("ul#list");

var box_orig    = list.children('.box');
var car_orig    = list.children('.car');

And $(this)

 $('#list li').each(function () {
     if ($.inArray($(this).attr('class'), show) == 0) {
         console.log($(this)); //-> Returns li.box / car or whatever list was selected
     }
 });

Re-edit: Re-Re-edit:

I realized that replacing the data breaks anything, so replacing goes out of the question, just show car/box_orig instead li.car/box

                $('#list li').each(
                function(){
                    //alert($.inArray($(this).attr('class'),show) );
                    if ($.inArray($(this).attr('class'),show) == 0)
                    {
                        if($(this).attr('class') == 'box')
                        {
                             --> show box_orig, which contains lis with info BUT DO NOT REPLACE THE DATA, just show the box_orig instead of $(this) = li.box
                        }
                        if($(this).attr('class') == 'car')
                        {
                             --> show car_orig, which contains lis with info BUT DO NOT REPLACE THE DATA, just show the box_orig instead of $(this) = li.car
                        }
                        console.log($(this));
                    }

html:

jQuery(li.car)  result...rifting (line 703)
jQuery(li.car)  result...rifting (line 703)
jQuery(li.car)  result...rifting (line 703)
jQuery(li.car)  result...rifting (line 703)
jQuery(li.car)  result...rifting (line 703)
jQuery(li.car)  result...rifting (line 703)
jQuery(li.car)  result...rifting (line 703)
jQuery(li.car)  result...rifting (line 703)

and each li.car contains data (img and text)

解决方案

Solution:

var list              =   $("ul#list");

var box_orig    = list.children('.box');
var car_orig    = list.children('.car');

...
$('#list li').each(
    function(){
        //alert($.inArray($(this).attr('class'),show) );
        if ($.inArray($(this).attr('class'),show) == 0)
        {
            if($(this).attr('class') == 'box')
            {
                list.append(box_orig);
            }
            if($(this).attr('class') == 'car')
            {
                list.append(car_orig);
            }
        }
        ...

这篇关于jQuery show car_orig if $(this).attr(.class)==“car”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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