Javascript-форум (https://javascript.ru/forum/)
-   jQuery (https://javascript.ru/forum/jquery/)
-   -   На одну кнопку два действия! (https://javascript.ru/forum/jquery/77817-na-odnu-knopku-dva-dejjstviya.html)

Evgeniy2019123 25.06.2019 10:40

На одну кнопку два действия!
 
Надо на одну кнопку повесить два действия!
В плане я нажал все поля стали доступными после етого еще раз нажал и все поля стали опять readonly
$('#start_change').click(function(){
      $('.changeable').removeAttr('readonly');
      $('#start_change').attr('id','end');
  });
    $('#end').click(function(){
        alert('END');
  });

Но почему не работает так.

Evgeniy2019123 25.06.2019 10:41

Цитата:

Сообщение от Evgeniy2019123 (Сообщение 509430)
Надо на одну кнопку повесить два действия!
В плане я нажал все поля стали доступными после етого еще раз нажал и все поля стали опять readonly
$('#start_change').click(function(){
      $('.changeable').removeAttr('readonly');
      $('#start_change').attr('id','end');
  });
    $('#end').click(function(){
        alert('END');
  });

Но почему не работает так.

Ну тоесть первое действие происходит ! А вот второе нет ! Тоесть поля стают доступны и меняется id у кнопки но не выполняетса сценарий по клику на id 'end'!

ksa 25.06.2019 10:42

Evgeniy2019123, ты хоть бы пример тестовый полный сделал...

рони 25.06.2019 10:44

Evgeniy2019123,
строка 5 нельзя поставить клик на то чего нет!!!

рони 25.06.2019 10:51

Evgeniy2019123,
<!DOCTYPE html>

<html>
<head>
  <title>Untitled</title>
  <meta charset="utf-8">
  <style type="text/css">
  </style>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>

  <script>
$(function() {
  var n = true;
  $('#start_change').click(function(){
      $('.changeable').prop('readonly', n = !n);
  });
});
  </script>
</head>

<body>
<button id="start_change">click</button>
<input type="text" class="changeable"  readonly="readonly">
<input type="text" class="changeable"  readonly="readonly">
<input type="text" class="changeable"  readonly="readonly">
<input type="text" class="changeable"  readonly="readonly">
<input type="text" class="changeable"  readonly="readonly">
</body>
</html>

Evgeniy2019123 25.06.2019 11:07

Цитата:

Сообщение от рони (Сообщение 509434)
Evgeniy2019123,
<!DOCTYPE html>

<html>
<head>
  <title>Untitled</title>
  <meta charset="utf-8">
  <style type="text/css">
  </style>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>

  <script>
$(function() {
  var n = true;
  $('#start_change').click(function(){
      $('.changeable').prop('readonly', n = !n);
  });
});
  </script>
</head>

<body>
<button id="start_change">click</button>
<input type="text" class="changeable"  readonly="readonly">
<input type="text" class="changeable"  readonly="readonly">
<input type="text" class="changeable"  readonly="readonly">
<input type="text" class="changeable"  readonly="readonly">
<input type="text" class="changeable"  readonly="readonly">
</body>
</html>

Спасибо

Evgeniy2019123 25.06.2019 11:12

Цитата:

Сообщение от ksa (Сообщение 509432)
Evgeniy2019123, ты хоть бы пример тестовый полный сделал...

<!DOCTYPE html> <html> <head> <script src="https://code.jquery.com/jquery-3.4.1.min.js" integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script> <title> Test </title> </head> <body> <button id='start_change'>Change</buuton> <input class='changeable' type='text' value='test'> <input class='changeable' type='text' value='test'> <input class='changeable' type='text' value='test'><input class='changeable' type='text' value='test'> </body> </html>

Evgeniy2019123 25.06.2019 11:13

Всем спасибо !


Часовой пояс GMT +3, время: 05:34.