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