0
A
回答
0
定义准备对文档的变量
var focusedInput;
如果焦点更改到任何输入商店输入focusedInput
focusedInput = $(this);
上的div点击编写代码
$('div.num-button').click(function(){
//some code here
$(focusedInput).focus(); //handle null exception
});
0
我知道这是非常晚,但是,如果其他人来寻找这个答案可能会有所帮助。
正如@anil所说,创建一个变量,您可以在其中存储您关注的输入。然后,当你专注于你的输入时,将元素存储在变量中。现在当您点击您的“键盘”时,获取该值并将其添加到焦点变量输入值。
这里是my fiddle,我从你原来的小提琴分支。
这是代码:
var focused;
// Stored the input
$('input').focus(function() {
focused = $(this);
});
// Listen for clicks on the number button
$('.num-button').click(function(){
// Get the value of the number button that was clicked as string
var intVal = $(this).find('span').text().toString();
// Make sure that we have a focused input
if(typeof focused != 'null' || typeof focused != 'undefined') {
// Only add numbers to the input field
if(intVal != "DONE" && intVal != "Del") {
// Get the values as strings
var curVal = focused.val().toString(),
newVal = curVal + intVal;
focused.val(newVal);
} else if (intVal == "Del") {
// Clear the value if the Del "key" was clicked.
focused.val('');
}
}
});
相关问题
- 1. 防止元素变得焦点
- 2. 防止元素失去焦点
- 3. 如何防止元素失去焦点?
- 4. 防止某些元素受到焦点
- 5. 焦点防止onclick
- 6. 如何防止自定义控件的元素变得焦点?
- 7. 是否有可能防止隐藏的元素跳入焦点
- 8. 防止LostFocus在儿童元素失去焦点时被触发
- 9. 防止初始焦点
- 10. 选择元素 - 防止选择更改
- 11. 选择当前的焦点元素
- 12. 如何防止/停止焦点到下一个输入文本元素?
- 13. 将焦点添加到焦点子元素上的父元素
- 14. 对元素焦点
- 15. 防止CSS继承所选元素的儿童
- 16. 防止选中div中的所有元素。 \
- 17. 如何防止继续点击元素?
- 18. snapjs防止关闭元素点击
- 19. jquery:防止点击div内关闭它...所有元素
- 20. 焦点错误的CSS Safari元素+元素选择器?
- 21. 防止元素参与文本选择
- 22. 防止固定元素在移动Safari中的输入焦点上跳跃
- 23. 如何通过IE11中的标签防止SVG元素获得焦点?
- 24. js中的焦点元素
- 25. 我该如何防止我的WPF TreeView聚焦所选的TreeViewItem
- 26. 的Python:SYS防止元素
- 27. 如何防止自定义元素行选择点击UI-GRID
- 28. 防止“快速”点击UI元素选择文本?
- 29. 防止含有元素时,子元素上点击
- 30. 固定位置div可防止焦点在其元素间移动时滚动
如果你避免这种情况的点击不会在您需要的DIV被获取,而在div点击返回处理焦点输入。 – slash197 2013-04-23 06:19:07
你最好用一些代码而不是截图来制作一个jsFiddle简单的例子。 – 2013-04-23 06:19:58
重点应该来还是不应该来输入字段? – 2013-04-23 06:21:31