我有很多在這信息的頁面,如果用戶點擊了一個鏈接和瀏覽器的搜索欄上彈出,因爲它會如果他們按下Ctrl鍵+˚F這將是很好。我可以查詢數據庫,因爲信息來自那裏,但我不想重新加載鏈接點擊頁面。是否有可能使用Jquery模擬Ctrl + F組合鍵?
6
A
回答
6
2
有一些插件,讓你這樣做,例如:https://github.com/jeresig/jquery.hotkeys
2
我知道這個職位是舊的,但我想我解決了這個使用jquery:
//i am assuming you are searching through a table...
//search input field listening for key pressed
$('.search_input').keyup(function (e) {
//listening if the key pressed is the enter button
if (e.which === 13) {
//inserting the value of textfield content, you can add if statement to check if the field is null or empty
var search_param = $(this).val();
//value of field stored into a variable
$('td').removeAttr('class');
//remove all classes attributed to a td AND search all td to find the one that march the search parameter
if ($('td:contains("' + search_param + '")').html() !== undefined) {
//if there is any td that has that record... then check for the closest tr and add a class with item_found as value
$('td:contains("' + search_param + '")').closest('tr').attr('class', 'item_found');
//add some highlight to it.
$('td:contains("' + search_param + '")').closest('tr').css({background:'yellow',color:black});
//then scroll to the item
$(window).scrollTop($('.item_found').first().offset().top);
} else {
//if item is not found display no result found
alert("Sorry no result found")
}
}
});
相關問題
- 1. 如何模擬Ctrl-S組合鍵?
- 2. linux組合鍵[Ctrl +,]和[Ctrl +。]被禁用?
- 3. 在頁面加載時,發送/模擬組合鍵[CTRL + L]
- 4. 是否有可能使用Moq在C#中模擬模擬的「類型名稱」?
- 5. 是否有可能僅使用響應變量來擬合線性模型?
- 6. 使用jQuery模擬按鍵
- 7. 使用jQuery模擬按鍵
- 8. 是否有可能在JavaScript只是用Ctrl + C複製圖像
- 9. 是否有可能使用jQuery
- 10. 是否有可能使用extract()和數組鍵名「some.key」?
- 11. 是否有可能在F#中結合多個屬性?
- 12. 是否有可能組合框的jQuery自動通過輸入
- 13. jquery模仿按鍵「ctrl +」
- 14. 是否有可能在JSF 2中使用複合組件的模板?
- 15. 是否可以在頁面中禁用Ctrl + F查找?
- 16. 是否有可能爲F#元組創建擴展方法
- 17. 是否可以使用Dev Express TdxBarSubItems模擬TMenuBreak功能?
- 18. 是否按下'Ctrl'鍵?
- 19. 模擬右Shift + Ctrl鍵與SendKeys.Send()
- 20. .NET模擬按Ctrl + Alt + Del鍵的SendKeys
- 21. Google Chrome是否有任何擴展程序可讓我在多個標籤上使用查找功能(CTRL + F)?
- 22. 是否可以使用c#來模擬ms-access的功能?
- 23. 是否有可能在rails中有複合外鍵?
- 24. 是否可以使用JPA和CriteriaBuilder組合鍵進行排序
- 25. 是否有可能使ListView和TextView的動態組合?
- 26. 模擬亞行終端按鍵組合
- 27. 如何模擬使用C#的CTRL + V按鍵(粘貼)
- 28. 我可以確定Ctrl鍵是按下Ctrl還是Right Ctrl?
- 29. 是否可以模擬Activator.GetObject()?
- 30. 是否可以模擬iframe?
http://stackoverflow.com/questions/832059/definitive-way-to-trigger-keypress-events-with-jquery – Neal
[通過網站上的按鈕使用瀏覽器搜索(Ctrl + F)?]可能的重複(HTT p://stackoverflow.com/questions/8080217/use-browser-search-ctrlf-through-a-button-in-website) – Sheepy