- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
代码示例 http://jsfiddle.net/rigaconnect/3Mcxv/6/
这是具有以下行为的 javascript:在输入字段中输入一些值;然后按住 ctrlKey 并用鼠标在输入字段下方单击;上面输入字段的值被复制到下面。
$(document).ready(function(){
$("input").on('click', function(e) {
var name1 = $(this).closest('tr').prev().find('td:eq('+$(this).closest('td').index()+')').find('input').val();
if(e.ctrlKey) $(this).val(name1).trigger('change');
});
});
以我想要的相同方式:如果我按住 shiftKey 并按下底部箭头按钮,则当前输入字段中的值将显示在下方的输入字段中。这是我试过的代码:
$(document).ready(function(){
$("input").keyup(function(e) {
var name1 = $(this).closest('tr').prev().find('td:eq('+$(this).closest('td').index()+')').find('input').val();
if(e.shiftKey) $(this).val(name1).trigger('change');
});
});
但是,如果我在输入字段中输入一些值,然后按住 shiftKey 并按下底部箭头按钮,值将从当前输入字段中消失。我需要该值保留在当前输入字段中,另外相同的值出现在正下方的输入字段中。
我想这是因为 prev().find
它发现 previous 是空白的。找到电流的正确代码是什么?我更改为 $(this).find
但没有工作....
最佳答案
这是您想要的功能吗?
http://jsfiddle.net/xQxGa/11///更新
$(document).ready(function () {
var isShiftPressed = false,
shiftCode = 16, // shift key code
downArrowCode = 40, // down arrow key code
$table = $('table'),
$inputs = $('input',$table);
$table
.delegate('input', 'keydown', function(e) {
if(e.which===shiftCode){
// shift was pressed
isShiftPressed = true;
} else if(isShiftPressed && e.which===downArrowCode){
// shift and down arrow were pressed
var newVal = this.value,
i = $inputs.index(this),
next = $inputs.eq(i+1);
if(next){
// move value and focus to the next
next.val(newVal)
.focus();
}
}
})
.delegate('input', 'keyup', function(e) {
// no key pressed anymore
isShiftPressed = false;
});
});
尝试查看 jQuery 页面中的示例。
关于Javascript keyup shiftKey 不是预期的行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17029864/
我创建了一个 keyup() 函数,代码在这里 $(document).ready(function() { var scntDiv = $('#add_words'); var wo
我希望它只在 keyup 而不是之前触发。有人可以帮忙吗? $(function() { $('#acf-field_5a32085c7df98-field_5a3208f87df99').on('k
在 Chrome 30.0.1599.101 和 IE 11 中,输入选择器无法在 Firefox 25.0.1 中正常工作 在 Chrome/IE 中损坏: $(document).ready(fu
在我为工作而构建的网站上,我们有一个搜索栏,用户可以在其中输入内容以搜索存储在一组元素数据中的各个字段。当他们开始输入时,问题出现在较慢的浏览器中。 我尝试做的是以下操作,使用 jQuery Defe
我正在尝试使用 vanilla js 编写一些简单的东西来在用户按下回车键时触发一个函数。我在下面找到了一些代码,但我不确定如何让它工作,因为该函数没有名称。 function (event) {
场景如下: 我有一个内容可编辑的 div。我还有一个文本区域,其中 .keyup() 上发生了一些事情。 我需要这样,在content editable div的keyup()上,将contented
有一个输入文本会在“onkeyup”事件上触发一个函数。当该函数触发时,我将使用 .on("keyup") 方法绑定(bind)一个“keyup”事件,以获取最后按下的键以查明它是否是字母数字,以便触
我想知道如何对同一个 #id 执行 .keyup() 和 .click() ? 即本质上,我想在用户尝试点击 enter 或点击 #search 按钮时验证 #id 。 非常感谢 最佳答案 $('#f
我必须在这里使用jquery keyup来检测用户是否输入任何文本,但我的问题是如果用户使用鼠标粘贴文本,它将无法检测到它,你能告诉我原因吗? 这是我的源代码: $("textarea").keyup
我正在尝试创建一个输入字段,用户只能在其中输入数字。这个功能对我来说已经可以正常工作了: $('#p_first').keyup(function(event){ if
我正在尝试编写类似于“占位符”polyfill 的内容。我想捕获输入字段上的 keyup 事件并获取用户输入的字符,所以我有以下代码: $elem.on('keyup',function(e){
我想我已经弄清楚了......请参阅我的评论。抱歉。 我有一个 JSON Web 服务,它在某个 keyup() 事件上调用,该事件根据输入检索一些数据。我想在输入任何内容之前加载一组初始数据。我正在
所以我使用 Keyup 来计算输入字段的总数。到目前为止,一切都很好。但现在我想这样做:如果选中#a 复选框,则将总金额加 12。如果没有,则添加 0。 我的代码基于此:http://jsfiddle
我在弄清楚为什么 keyup 事件在以下情况下不起作用(不显示警报)时遇到问题,我对表单使用 bootstrap 3,但我不认为 form-control取消键盘输入? HTML: jQuery:
我正在构建一个搜索表单,.keyup 中的 ajax 函数可以有不同的参数,我想通过检查是否存在另一个值来检查是否需要包含此参数。这是我现在拥有的: var delay = (function() {
我的 html 和 jquery 代码 Insert title here td { min-height: 50px; min-width: 50px; }
每次我按下键盘上的一个键,它都会将 $(this).val(""); 设置为 null,并且 score 变量将为 -2 . initialize: function() { var scor
我是 javascript 及其事件的新手。这是我的表格 html 代码,其中有收入标题及其各自的价格。 sn Title of income
我有一个这样的表: 当数量/价格变化小计也发生变化时,我想制作Javascript。我的js: $("#invoice_item").delega
我正在 js 中制作字符计数器,但 keyup 事件不起作用??? $(document).ready(function() { function countingCharacter(elemen
我是一名优秀的程序员,十分优秀!