Codeigniter databse uchun qator sifatida ajax uchun bir xil sinf nomi bilan bir nechta id qiymatlarini qanday yuboriladi?

Salom, men ajaxdan foydalangan ma'lumotlar bazasiga bir xil identifikator nomi bilan bir nechta id qo'yishga harakat qilyapman, lekin bu qiymatlarni faqat bir nechta qiymatlarni yuborishim mumkin bo'lgan barcha qadriyatlarni emas, faqat qadriyatlarni tanlaydi.

Bu mening kodim  ko'rinish

  • <div class="hour_slots_available" id="01_02">01:00 - 02:00</div>
  • 
    
  • <div class="hour_slots_available" id="02_03">02:00 - 03:00</div>
  • 
    
  • <div class="hour_slots_available" id="03_04">03:00 - 04:00</div>
  • 
    
  • <div class="hour_slots_available" id="04_05">04:00 - 05:00</div>
  • 
    
  • <div class="hour_slots_available" id="05_06">05:00 - 06:00</div>
  • 
    
  • <div class="hour_slots_available" id="06_07">06:00 - 07:00</div>
  • 
    
  • <div class="hour_slots_available" id="07_08">07:00 - 08:00</div>
  • 
    
  • <div class="hour_slots_available" id="08_09">08:00 - 09:00</div>
  • 
    
  • <div class="hour_slots_available" id="09_10">09:00 - 10:00</div>
  • now on click 
    <button class="btn btn-success" onclick="gethourprice();">Get Prices</button>
    

    Bu funktsiya chaqirilganda, agar ular tanlangan bo'lsa, sinfga soatlik slotlar bilan divni ma'lumotlar bazasiga ega bo'lishini xohlayman.

    bu yerda

    <script type="text/javascript">    
    function gethourprice()
    {    
    var selected_ids = document.getElementsByClassName('hour_slots_available ').id;
    alert(selected_ids);    
    }
    </script>
    

    ammo ogohlantiruvchi tanlanganlar faqat bitta id 12_01 raqamini ko'rsatsa chaqiradi bu erda qanday muammo bor? Menga aytolasanmi ?

    0

    6 javoblar

    Buni sinab ko'ring: siz barcha moslamalarni mos sinf bilan birga olsangiz, ob'ektni yineleyin va barcha identifikatorlarni to'plang, kodni pastga qarang

    function gethourprice()
    {    
    var selectedIds="";
    var selectedObject = document.getElementsByClassName('hour_slots_available ');
    for(var i=0;i
    3
    qo'shib qo'ydi
    Sizga yordam berishdan mamnunman
    qo'shib qo'ydi muallif Bhushan Kawadkar, manba
    Rahmat shukr, u juda ishlagan @BhushanKawadkar ishiga ishlaydi
    qo'shib qo'ydi muallif Himanshu Goyal, manba

    Bu yerda bu yerdan foydalanishingiz kerak

    function gethourprice(){
    
        var selected_ids = document.getElementsByClassName('hour_slots_available ').id;
        for(var i = 0; i < selected_ids.length; i++) {
           alert(selected_ids[i]);//Will alert all ids in loop
       }
    }
    
    1
    qo'shib qo'ydi

    arrayDiv qatoridagi barcha qiymatlarni olishingiz mumkin va endi ajralib chiqish uchun arrayDiv qatorini osongina olishingiz mumkin.

    Kod ...

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

    var arrayDiv = new Array();;
    
    $('#getv').click(function(){
    $('.hour_slots_available').each(function(i){
      arrayDiv.push($(this).attr('id'));
    });
    console.log(arrayDiv);
    // you can call Your ajax here 
    });
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    
  • <div class="hour_slots_available" id="01_02">01:00 - 02:00</div>
  • 
    
  • <div class="hour_slots_available" id="02_03">02:00 - 03:00</div>
  • 
    
  • <div class="hour_slots_available" id="03_04">03:00 - 04:00</div>
  • 
    
  • <div class="hour_slots_available" id="04_05">04:00 - 05:00</div>
  • 
    
  • <div class="hour_slots_available" id="05_06">05:00 - 06:00</div>
  • 
    
  • <div class="hour_slots_available" id="06_07">06:00 - 07:00</div>
  • 
    
  • <div class="hour_slots_available" id="07_08">07:00 - 08:00</div>
  • 
    
  • <div class="hour_slots_available" id="08_09">08:00 - 09:00</div>
  • 
    
  • <div class="hour_slots_available" id="09_10">09:00 - 10:00</div>
  • now on click 
    <button id="getv" class="btn btn-success" >Get Prices</button>
    </div> </div>

    1
    qo'shib qo'ydi

    Lekin ogohlantirish tanlagan_ideklarni chaqirganda faqat bitta id 12_01ni ko'rsatishi mumkin   bu erda qanday muammo bor? Siz menga aytasizmi?

    Document.getElementsByClassName bitta satrni emas, balki bir nechta satrlarni qaytaradi.

    Biror id qiymatini so'raganingizda, siz almashgan kod siz aniqlanmaganligini yodda tuting. Shunday qilib, .id qismini document.getElementsByClassName ('hour_slots_available') .id saytida olib tashlashingiz kerak va ayrim satrlarni o'zgartirish uchun tanlangan_idlardan ustunga aylantirilsin.

    Misol:

    function gethourprice() {
      var selected_ids = document.getElementsByClassName('hour_slots_available ');
      for (id in selected_ids) {
        alert(id);
      };
    };
    gethourprice();
    

    CodePen demo (using console.log instead of alert):

    http://codepen.io/robee/pen/GWZxor

    0
    qo'shib qo'ydi

    Siz bunday narsani ishlatishingiz kerak

    function GetAllIds(){
        var idsArray = [];
        $(".hour_slots_available").each(function(){
            idsArray.push($(this).attr("id"));
            //or may be a comma seperated list
           //use jquery. write less do more :)
        });
        return idsArray;
    }
    
    0
    qo'shib qo'ydi

    getElementsByClassName vazifasi elementlarning qatorini qaytaradi. lekin JavaScript native funksiyasi emas edi. getElementsByClassName funktsiyasidan attribut olish brauzeringiz tomonidan bog'liq bo'ladi. sizning elementlar qatorini olish uchun gethourprice-ni tahrirlashingiz kerak. bu erda namuna

    <script type="text/javascript">
    
        function gethourprice(){
    
            var selected_ids = document.getElementsByClassName('hour_slots_available');
            var ids = [];
            for (var i = 0;  i < selected_ids.length; i++) {
                ids.push(selected_ids[i].id)
            }
            alert(ids);
        }
    </script>
    
    0
    qo'shib qo'ydi
    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

    PhP |BotsUz
    PhP |BotsUz
    93 ishtirokchilar

    Phpni o'rganishni Hohlasangiz https://t.me/joinchat/AAAAAE-KRc5dd5tPMmGmWA A'zo bo'lin