Kirish yorlig'i qiymatini ochiladigan ro'yxatidan sozlab bo'lmadi

Men ochiladigan ro'yxatdan kirish qiymatini belgilashga harakat qilaman, lekin u men uchun ishlamaydi. Bu mening kodim:

<form>
    
    <input type="text" id="output">
</form>
$('#color').bind('change', function() {
    $('#output').html($(this).find(':selected').html() + '
'); console.log($(this).find(':selected').html()); });

<input type = "text" id = "output"> <div id = "output"> </div> bilan o'zgartirilganda ishlaydi. Har qanday echim?

2
Agar siz jQuery versiyasidan foydalansangiz? .on() dan foydalaning
qo'shib qo'ydi muallif guradio, manba
Bundan tashqari, $ ('# output'). val() bu kod emas, balki .hml() ;
qo'shib qo'ydi muallif Toni Michel Caubet, manba

6 javoblar

#output elementi kirish , shuning uchun val() kodini emas, html() uning qiymatini belgilash.

Bundan tashqari, bind() eskirganligini ham unutmang. Buning o'rniga change() yoki ni ('o'zgartirish') ishlatishingiz kerak. Buni ko'ring:

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

$('#color').on('change', function() {
  $('#output').val($(this).find(':selected').text());
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form>
  
  <input type="text" id="output">
</form>
</div> </div>
3
qo'shib qo'ydi
Rahmat juda ko'p ishlaydi
qo'shib qo'ydi muallif Mouhssine, manba
skriptdan + "
" ni o'chirib tashlashi kerak, chunki u qiymat bilan joylashtirilgan bo'lishi kerak, shuning uchun <script type = "text/javascript"> $ ('# color') bo'lishi kerak .Bind ('o'zgarish', function() {$ (' ($ (this) .find (": selected") matn ()); console.log ($ (this) .find (': tanlangan'); html ();});
qo'shib qo'ydi muallif Mouhssine, manba

Ushbu misolni ko'ring,

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

$('#color').bind('change', function() {
    $('#output').val($('#color option:selected').text());
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form>
    
    <input type="text" id="output">
</form>
</div> </div>

Variantlar matnini tanlaganingizda o'zgarishlar qildim.

Umid qilamanki bu yordam beradi.

3
qo'shib qo'ydi
rahmat
qo'shib qo'ydi muallif Mouhssine, manba

with input element it should be val() not html()

$(document).on('change','#color', function() {
    $('#output').val($(this).find(':selected').html());
});
1
qo'shib qo'ydi

Buni ko'ring:

$(document).ready(function() {
  $('#color').on('change', function() {
    //alert( this.value );
     $('#output').val(this.value);
  });
});
1
qo'shib qo'ydi

Kirish teglari doimo qiymatga ega, shuning uchun kodni quyidagi holatda o'zgartirishingiz kerak.

<script type="text/javascript">
$(document).on('change','#color', function(){

    $('#output').val($(this).find(':selected').html() + '
'); }); </script>
0
qo'shib qo'ydi
<script type="text/javascript">
$('#color').bind('change', function(){
    $('#output').val($(this).find(':selected').html() + '
'); console.log($(this).find(':selected').html()); });
0
qo'shib qo'ydi
Rahmat R.Makkrozon kabi bir xil javobni
qo'shib qo'ydi muallif Mouhssine, manba
PhP |BotsUz
PhP |BotsUz
93 ishtirokchilar

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