点击更换价值,SHIFT +单击使用jQuery附加价值 [英] click to replace value, shift + click to append value using jquery
问题描述
我有一个项目的清单。结果
当我点击这些项目的任何,我复制的其 ID
- 值成表格文本
-field。结果
每次我点击,它取代了值,默认情况下是正确的。不过,我想补充一下,是用户的方式来稳定自己的键盘上的按键,当他们再单击,他们只是 .append
无论他们刚刚点击在同一个表单字段。
I have a list with items.
When I click any of these items, I copy its id
-value into a form text
-field.
Everytime I click, it replaces the value, which is correct by default. But what I would like to add, is a way for the user to hold down a key on their keyboard, and when they then click, they just .append
whatever they just clicked into the same form field.
下面是我的jQuery- code我使用的第一/默认方案:
Here's my jQuery-code I'm using for the first/default scenario:
$(function(){
$('ul#filter-results li').click(function(){
var from = $(this).attr('id'); // get the list ID and
$('input#search').val(from+' ').keyup(); // insert into text-field then trigger the search and
$('input#search').focus(); // make sure the field is focused so the user can start typing immediately
});
});
有没有办法实现某种键盘键侦听的方法吗?结果
是这样的:
Is there a way to implement some sort of keyboard key-listener?
Something like:
if (e.shiftKey){
.append('this text instead')
}
还没有尝试过,看看 Shift键
是即使在这里,任何有效的名称
haven't tried out to see if shiftKey
is even any valid name here
推荐答案
Shift键
是事件对象的属性之一,并且是有效的使用。试试这个:
shiftKey
is of one of the properties of the event object and is valid to be used. try this:
$(document).on('keyup click', function(e){
if (e.shiftKey) {
$('input#search').focus()
$('input#search').val(e.target.id)
}
})
这篇关于点击更换价值,SHIFT +单击使用jQuery附加价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!