Enter tugmasi yordamida katakchani tanlang

Menda diqqat markazida bo'lsa bo'sh joy o'rniga, men uchun kerakli bo'lgan bir necha tasdiqlash qutisi bor. Quyidagi kod bitta tasdiqlash qutisi uchun ishlaydi, lekin bir nechta tasdiqlash xati kerak. Id tagining noyob bo'lishi kerakligini bilaman, lekin buni qanday qilishni bilmayman.

    $(document).ready(function() {
    $('#mycheckbox').on('keypress', function (event) {
        if (event.which === 13) {
            this.checked = !this.checked;
        }
    });
});

<input type="checkbox" name="Colors" value="Bike" id="mycheckbox">My text

Buni faqat checkbox id bilan birga emas, balki barcha tasdiqlash qutilarida ishlashga harakat qilaman.

Mana hozirgacha mening to'liq kodim:

`

<html>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-

latest.js"></script>
<script type="text/javascript">
$(document).ready(function() {
    $('input:checkbox').on('keypress', function (event) {
        if (event.which === 13) {
            $(this).prop('checked', !$(this).prop('checked'));
        }
    });
});
</script>

</head>
<body>

<script 

src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></

script>


<div class="taglist">
  
  
  
  
  
</div>
<script type="text/javascript">
function updateTextArea() {
  var allVals = $('#form1').data('initialVal'),
      lineCount = 1;
  $('.taglist :checked').each(function(i) {
    allVals+= (i != 0 || allVals.length > 0 ? "\r\n" : "") + $(this).val

();
    lineCount++;
  });
  $('#form1').val(allVals).attr('rows', lineCount);

}
$(function() {
  $('.taglist input').click(updateTextArea);

  $('#form1').data('initialVal', $('#form1').val());
  updateTextArea();
});
</script>

</body>
</html>

`

0
@Greg - Agar tasdiqlash qutisi bosilganda matn maydonini yangilaysiz. Change hodisasini, bu $ ('. Taglist kiritish') kabi o'zgartirish uchun yaxshiroq qilish (updateTextArea); . Keyin dastur kodini tekshirishdan so'ng, $ (this) .change (); ni chaqirib, o'zgarish hodisasini boshlang.
qo'shib qo'ydi muallif John S, manba
@Greg - Agar tasdiqlash qutisi bosilganda matn maydonini yangilaysiz. Change hodisasini, bu $ ('. Taglist kiritish') kabi o'zgartirish uchun yaxshiroq qilish (updateTextArea); . Keyin dastur kodini tekshirishdan so'ng, $ (this) .change (); ni chaqirib, o'zgarish hodisasini boshlang.
qo'shib qo'ydi muallif John S, manba
Iltimos, foydalanadigan HTMLni joylashtiring.
qo'shib qo'ydi muallif Daniel Corzo, manba
Faqatgina stackoverflow.com/a/35423812/1343917 bilan tasdiqlash qutisini tanlashingiz mumkin.
qo'shib qo'ydi muallif Dmitry Gonchar, manba
U ajoyib ishlaydigan ajoyib. Men bularning barchasini qadrlayman. Sizga katta rahmat!!!!
qo'shib qo'ydi muallif Greg, manba

11 javoblar

Selektorni o'zgartirishni bajarish kerak:

$('input[type=checkbox]')

Bu turdagi barcha yozuvlarni qaytaradi. Yana bir yondashuv, siz qiziqayotgan barcha tasdiqlash qutilarini sinfga berish va sinfni moslashtirmoqdamiz - agar siz ularni barchasiga qo'llashni xohlamasangiz, men ushbu yondashuvni taklif qildim. Shunday qilib, HTML:

<input type="checkbox" class="support-enter" />

Keyin jQuery tanlovi:

$('.support-enter')
3
qo'shib qo'ydi

Sounds like you are trying to get this to work on all checkboxes? In that case use $( ":checkbox" ) instead of $('#mycheckbox')

3
qo'shib qo'ydi
@Greg, dasturiy jihatdan tasdiqlash belgisini tekshirish o'zgarish-hodisani tetiklashiga olib kelmaydi, lekin buni $ (this) .change (); (bu $ ($) bu() o'zgarish ("o'zgarish ); (umid qilamanki, siz o'zgarish-hodisani klik-voqi emas, balki foydalanayotgan bo'lsangiz.
qo'shib qo'ydi muallif John S, manba
Yaxshi ishlashi uchun jQuery hujjatlari sizdan input: checkbox : checkbox emas, balki. Chunki : checkbox *: checkbox ga mos keladi.
qo'shib qo'ydi muallif John S, manba
@Greg, mening javobimga qarang.
qo'shib qo'ydi muallif Mihai Alexandru-Ionut, manba
Qiymat qiymati tekshirildi yoki katakchaning nomi bormi?
qo'shib qo'ydi muallif Blakethepatton, manba
Bunga erishildi. Katta rahmat. Sizlar juda tez !!!! Yordamingiz uchun barchangizga rahmat. Biroq, menda muammo bor. Buni matn maydoniga yuborish uchun katakchadan foydalanaman. Sichqonchani bosganimda u ajoyib ishlaydi. Enter tugmasi endi katakchani tanlab oladi, lekin qiymat matnga o'tkazilmaydi.
qo'shib qo'ydi muallif Greg, manba
Belgilangan qiymat
qo'shib qo'ydi muallif Greg, manba
Bunga erishildi. Katta rahmat. Sizlar juda tez !!!! Yordamingiz uchun barchangizga rahmat.
qo'shib qo'ydi muallif Greg, manba
@JohnS Men siz xohlaganingizni ko'rsatish uchun mening savolimni tahrirladim. Javascript bilan uzr so'rayman. Bu yordam berdimi?
qo'shib qo'ydi muallif Greg, manba

Buning o'rniga classes ni ishlatishingiz kerak.

<input type="checkbox" name="Colors" value="Bike" class="mycheckbox">My text

Jquery

$('.mycheckbox').on('keypress', function (event) {
    if (event.which === 13) {
        $(this).prop('checked', !$(this).prop('checked'));
    }
});

Another method is to use a type selector in order to get the input elements with certain type.

$('input[type=checkbox]')

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

$(':checkbox').on('keypress', function (event) {
    if (event.which === 13) {
        $(this).prop('checked', !$(this).prop('checked'));
        $('textarea').html($(this).prop('checked').toString());
    }
});
<script src="https://ajax.googleapis.com/ajax/libs/Jquery/2.1.1/Jquery.min.js"></script>
<input type="checkbox" name="Colors" value="Bike" class="mycheckbox">My text
</div> </div>
1
qo'shib qo'ydi
@Downvoter, iltimos, sababingizni tushuntiring.
qo'shib qo'ydi muallif Mihai Alexandru-Ionut, manba
Men pastga emasman, lekin nima uchun biz : checkbox pseudo-sinfidagi selektorga kirish imkoniga ega bo'lgan sinf yaratmoqdamisiz?
qo'shib qo'ydi muallif Blakethepatton, manba

Buning o'rniga classes ni ishlatishingiz kerak.

<input type="checkbox" name="Colors" value="Bike" class="mycheckbox">My text

Jquery

$('.mycheckbox').on('keypress', function (event) {
    if (event.which === 13) {
        $(this).prop('checked', !$(this).prop('checked'));
    }
});

Another method is to use a type selector in order to get the input elements with certain type.

$('input[type=checkbox]')

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

$(':checkbox').on('keypress', function (event) {
    if (event.which === 13) {
        $(this).prop('checked', !$(this).prop('checked'));
        $('textarea').html($(this).prop('checked').toString());
    }
});
<script src="https://ajax.googleapis.com/ajax/libs/Jquery/2.1.1/Jquery.min.js"></script>
<input type="checkbox" name="Colors" value="Bike" class="mycheckbox">My text
</div> </div>
1
qo'shib qo'ydi
@Downvoter, iltimos, sababingizni tushuntiring.
qo'shib qo'ydi muallif Mihai Alexandru-Ionut, manba
Men pastga emasman, lekin nima uchun biz : checkbox pseudo-sinfidagi selektorga kirish imkoniga ega bo'lgan sinf yaratmoqdamisiz?
qo'shib qo'ydi muallif Blakethepatton, manba

input [type = "checkbox"] dan foydalanishingiz mumkin yoki har bir tasdiq qutisiga sinf qo'sha olasiz va ha noaniq bo'lishi kerak:

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

$(document).ready(function() {
  $('input[type="checkbox"]').on('keypress', function(event) {
    if (event.which === 13) {
      this.checked = !this.checked;
    }
  });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="checkbox" name="Colors" value="Bike" id="mycheckbox1">My text
<input type="checkbox" name="Colors" value="Bike" id="mycheckbox2">My text
<input type="checkbox" name="Colors" value="Bike" id="mycheckbox3">My text
<input type="checkbox" name="Colors" value="Bike" id="mycheckbox4">My text
</div> </div>
1
qo'shib qo'ydi

input [type = "checkbox"] dan foydalanishingiz mumkin yoki har bir tasdiq qutisiga sinf qo'sha olasiz va ha noaniq bo'lishi kerak:

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

$(document).ready(function() {
  $('input[type="checkbox"]').on('keypress', function(event) {
    if (event.which === 13) {
      this.checked = !this.checked;
    }
  });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="checkbox" name="Colors" value="Bike" id="mycheckbox1">My text
<input type="checkbox" name="Colors" value="Bike" id="mycheckbox2">My text
<input type="checkbox" name="Colors" value="Bike" id="mycheckbox3">My text
<input type="checkbox" name="Colors" value="Bike" id="mycheckbox4">My text
</div> </div>
1
qo'shib qo'ydi

Turli kirishlarni olish uchun atributli tanlovli dan foydalaning. checkbox quyidagi kabi:

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

$(document).ready(function() {
  $('input[type = "checkbox"]').on('keypress', function(event) {
    if (event.which === 13) {
      this.checked = !this.checked;
    }
  });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="checkbox" name="Colors" value="Bike">My text
<input type="checkbox" name="Colors" value="Bike">Other text
</div> </div>
1
qo'shib qo'ydi

Turli kirishlarni olish uchun atributli tanlovli dan foydalaning. checkbox quyidagi kabi:

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

$(document).ready(function() {
  $('input[type = "checkbox"]').on('keypress', function(event) {
    if (event.which === 13) {
      this.checked = !this.checked;
    }
  });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="checkbox" name="Colors" value="Bike">My text
<input type="checkbox" name="Colors" value="Bike">Other text
</div> </div>
1
qo'shib qo'ydi

Yoki ID tanlovi o'rniga sinf selektoridan foydalanishingiz mumkin. Tasdiqlash qutisiga ba'zi bir sinf qo'shing.

1
qo'shib qo'ydi

Yoki ID tanlovi o'rniga sinf selektoridan foydalanishingiz mumkin. Tasdiqlash qutisiga ba'zi bir sinf qo'shing.

1
qo'shib qo'ydi

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

$(document).on('keypress', function(event) {
  if (event.keyCode == 13) {
    $('#mycheckbox').prop('checked', true);
  }
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="checkbox" name="Colors" value="Bike" id="mycheckbox">
</div> </div>
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