Ro'yxatni raqamlashtirish uchun Javascript/Jquerydan foydalanish

Menda shunga o'xshash kichik HTML namunasi bor



Men o'zim bajargan narsam uchun HTMLni tahrir qila olmayman, lekin men asosan har bir sonini ma'lumotlar tomoniga kiritishim kerak - faqat JS ni ishlatish uchun



Har qanday fikr bormi?

1

6 javoblar

Ushbu oddiy kodni ko'ring,

<div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"> <div class="snippet-code">

$(document).ready(function(){
  $("ul>li").each(function(i,j){
     $(this).attr("data-slide-to",i);
  });
  console.log($("ul").html());
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
</div> </div>

Li katalogini oldim va uni har bir li kodini data-slide-to atributiga tayinladim.

Umid qilamanki bu yordam beradi.

1
qo'shib qo'ydi
: D Men nimani boshdan kechirish o'rniga aniq emas, deb hayron bo'ldim :) Xush kelibsiz!
qo'shib qo'ydi muallif rahulsm, manba
Yordam berishdan baxtiyorman va Stack Overflowga xush kelibsiz. Agar bu javob yoki sizning muammolaringizni hal qilsangiz, iltimos buni qabul qilingan deb belgilang.
qo'shib qo'ydi muallif rahulsm, manba
Rahmat, u mate ishladi. Siz hayron bo'ladigan bo'lsak, instagram karuselini ishlab chiqardim.
qo'shib qo'ydi muallif Taylor D Wright, manba

Ushbu kodni sinab ko'ring, bu sizga yordam beradi deb umid qilaman

<div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"> <div class="snippet-code">

$('ul>li').each(function(i, obj){
  $(this).attr('data-slide-to',i); 
})

  console.log($("ul").html());
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

</div> </div>

0
qo'shib qo'ydi

JQuery usulidan foydalanishingiz mumkin each() kodi li ning barcha nuqtalarini aylantirishi va data- * attributes kodini each() usulidan jQuery ma'lumotlar() usuli:

$('ul>li').each(function(index, value){
    $(this).data('slide-to', index);
})

Umid qilamanki bu yordam.

<div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"> <div class="snippet-code">

$('ul>li').each(function(index, value){
    $(this).data('slide-to', index);
})

//Debug
$('ul>li').each(function(i,v){
    console.log( $(this).data('slide-to') );
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

</div> </div>

0
qo'shib qo'ydi

Buni ko'ring ...

Core JS

var lis = document.querySelectorAll('li');
lis.forEach((element,index)=>{
element.setAttribute('data-slide-to',index);
});
console.log(lis);

Misol:

<div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"> <div class="snippet-code">

var lis = document.querySelectorAll('li');
lis.forEach((element,index)=>{
element.setAttribute('data-slide-to',index);
console.log(element);
});

</div> </div>

0
qo'shib qo'ydi

Buni ko'ring

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script>
$(document).ready(function(){

  $('ul li').each(function(i,el)
{
   $(el).attr('data-slide-to',i);//This is your rel value
});

});
</script>
0
qo'shib qo'ydi
@Taylor D Raytlar bu yordam beradi
qo'shib qo'ydi muallif Faraz, manba

Use each to iterate between li and change the value of data-slide-to with its index

<div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"> <div class="snippet-code">

$(document).ready(function(){
  $("li").each(function(index){
    $(this).attr("data-slide-to", index)
  })
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
</div> </div>

0
qo'shib qo'ydi
indeks kodini .each ga o'tkazganingizdan keyin uni ishlatmadingiz ...
qo'shib qo'ydi muallif Zze, manba
Ha, sen haqsiz ahmoqsan. Kodni yangiladim.
qo'shib qo'ydi muallif aje, manba
Javascript UZB
Javascript UZB
99 ishtirokchilar

@js_uzb @vuejs_uz @react_uz @nodejs_uz @angular_uz @ngTashkent @yiiframework_uz @laravel_uz @linux_uzbek @python_uz @swift_uzb —————— @uzdevgroup @UzGeeksGroup ——— @UzDev_Jobs @jobs_uzb