Использование Jquery keyPress () для захвата нажатий клавиш на клавиатуре [дубликат]

Вы можете использовать libmail: http://lwest.free.fr/doc/php/lib/index.php3?page=mail&lang=en

include "libmail.php";
$m = new Mail(); // create the mail
$m->From( $_POST['form'] );
$m->To( $_POST['to'] );
$m->Subject( $_POST['subject'] );
$m->Body( $_POST['body'] );
$m->Cc( $_POST['cc']);
$m->Priority(4);
//  attach a file of type image/gif to be displayed in the message if possible
$m->Attach( "/home/leo/toto.gif", "image/gif", "inline" );
$m->Send(); // send the mail
echo "Mail was sent:"
echo $m->Get(); // show the mail source

1
задан Adam 7 March 2016 в 14:06
поделиться

3 ответа

Используйте комбинацию клавиш / клавиш для переключения цвета:

$("button").keydown(function(e) {
    // Sets the color when the key is down...
    if(e.which === 13) {
    	$(this).css("background-color", "red");
    }
});
$("button").keyup(function() {
    // Removes the color when any key is lifted...
    $(this).css("background-color", "");
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button>
Test
</button>

2
ответ дан CodingIntrigue 22 August 2018 в 19:42
поделиться
  • 1
    Спасибо! Я думаю, что вам не хватает точки в $ («.botton») . – Adam 7 March 2016 в 14:20
  • 2
    @Adam Это селектор для любого элемента <button> :) .button выберет любой элемент с class="button" – CodingIntrigue 7 March 2016 в 14:24

Попробуйте следующий код

           $('.button').keypress(function(e){
              if(e.which == 13){
                  $(this).css('background-color','#FFF');
              }
            });

            $('.button').keyup(function(e){
              if(e.which == 13){
                  $(this).css('background-color','');
              }
            });
0
ответ дан Alpesh Jikadra 22 August 2018 в 19:42
поделиться

Попробуйте это

.clicked{
background:#fff !important;
}

$('.button').keydown(function(e){
      if(e.which == 13){
           $(this).addClass('clicked');
        }
 e.preventDefault();
  });
1
ответ дан SAGAR MANE 22 August 2018 в 19:42
поделиться
  • 1
    но тогда мне нужно удалить класс, нажатый на клавиатуру или что-то в этом роде? – Adam 7 March 2016 в 14:14
  • 2
    нет необходимости удалять .. oR $ (this) .removeClass ('inactive'). addClass ('clicked'); – SAGAR MANE 7 March 2016 в 14:15
Другие вопросы по тегам:

Похожие вопросы: