按鈕提交在url后添加字段_在輸入字段上定向單擊“清除”按鈕(X)

按鈕提交在url后添加字段

jQuery makes it easy to get your project up and running. Though it's fallen out of favor in recent years, it's still worth learning the basics, especially if you want quick access to its powerful methods.

jQuery使您可以輕松啟動和運行項目。 盡管近年來它不受歡迎,但仍然值得學習基礎知識,尤其是如果您想快速使用其強大的方法。

But while jQuery is a powerful library, it can't do everything. That's where having solid understanding of vanilla JavaScript comes in handy.

但是,盡管jQuery是一個功能強大的庫,但它無法完成所有工作。 在那里,對香草JavaScript有扎實的了解非常有用。

Say you have a Wikipedia Viewer project like this:

假設您有一個像這樣的Wikipedia Viewer項目:

$("#searchbox").keyup(function(event) {if(event.keyCode === 13) {$("#searchbutton").click();};
});$("#searchbutton").click(function() {var searchInput = document.getElementById("searchbox").value;searchInput = searchInput.toLowerCase();if(searchInput !== "") {var myRequest = new XMLHttpRequest();myRequest.open('GET','https://en.wikipedia.org/w/api.php?action=query&list=search&srsearch='+ searchInput + '&utf8=&format=json&origin=*');myRequest.onload = function() {var searchResults = JSON.parse(myRequest.responseText);$(".resultingarticles").empty();  for(i=0; i<10; i++) {var articleTitle = searchResults.query.search[i].title;var articleSnippet = searchResults.query.search[i].snippet;var articleId = searchResults.query.search[i].pageid;var articleLink = "https://en.wikipedia.org/?curid=" + articleId;$(".resultingarticles").append("<a href='" + articleLink + "' target='_blank'>" + "<div class='article'>" + "<p>"+articleTitle+"</p>" + "<p>" + articleSnippet + "</p>" + "</div>" + "</a>");};};myRequest.send();};
});

Everything is working as you expect – you can enter text into the search box, hit enter or the "Search" button, and see a list of Wikipedia articles.

一切都按預期運行-您可以在搜索框中輸入文本,按Enter或“搜索”按鈕,然后查看Wikipedia文章列表。

Because you're using type="search" on your input element, the Chrome browser will automatically add an "X" to the end of the input if there's text and you hover over the input. Note that other browsers might handle type="search" differently.

由于您在input元素上使用type="search" ,因此如果有文本并將鼠標懸停在輸入上,Chrome瀏覽器會自動在輸入末尾添加“ X”。 請注意,其他瀏覽器可能會不同地處理type="search"

When you click on the "X", the text disappears.

當您單擊“ X”時,文本消失。

But say you already have a list of articles, and when you clear the text, you also want to clear the populated articles:

但是說您已經有文章列表,并且在清除文本時,您還希望清除填充的文章:

It turns out that clicking the "X" in the search box fires a "search" event. jQuery doesn't support the "search" event, so you'll have to write an event listener in vanilla JavaScript:

事實證明,單擊搜索框中的“ X”會觸發“搜索”事件。 jQuery不支持“搜索”事件,因此您必須使用原始JavaScript編寫事件監聽器:

document.getElementById("searchbox").addEventListener("search", function(event) {$(".resultingarticles").empty();  
});

Now when a search event is fired, you can use jQuery to clear the div element with the articles:

現在,當觸發搜索事件時,您可以使用jQuery清除以下文章中的div元素:

翻譯自: https://www.freecodecamp.org/news/targeting-click-of-clear-button-x-on-input-field/

按鈕提交在url后添加字段

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/390206.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/390206.shtml
英文地址,請注明出處:http://en.pswp.cn/news/390206.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

429. N 叉樹的層序遍歷

429. N 叉樹的層序遍歷 給定一個 N 叉樹&#xff0c;返回其節點值的層序遍歷。&#xff08;即從左到右&#xff0c;逐層遍歷&#xff09;。 樹的序列化輸入是用層序遍歷&#xff0c;每組子節點都由 null 值分隔&#xff08;參見示例&#xff09;。 - 示例 1&#xff1a;輸入…

javascript如何阻止事件冒泡和默認行為

阻止冒泡&#xff1a; 冒泡簡單的舉例來說&#xff0c;兒子知道了一個秘密消息&#xff0c;它告訴了爸爸&#xff0c;爸爸知道了又告訴了爺爺&#xff0c;一級級傳遞從而以引起事件的混亂&#xff0c;而阻止冒泡就是不讓兒子告訴爸爸&#xff0c;爸爸自然不會告訴爺爺。下面的d…

89. Gray Code - LeetCode

為什么80%的碼農都做不了架構師&#xff1f;>>> Question 89. Gray Code Solution 思路&#xff1a; n 0 0 n 1 0 1 n 2 00 01 10 11 n 3 000 001 010 011 100 101 110 111 Java實現&#xff1a; public List<Integer> grayCode(int n) {List&…

400. 第 N 位數字

400. 第 N 位數字 在無限的整數序列 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, …中找到第 n 位數字。 注意&#xff1a;n 是正數且在 32 位整數范圍內&#xff08;n < 231&#xff09;。 示例 1&#xff1a; 輸入&#xff1a;3 輸出&#xff1a;3 示例 2&#xff1a; 輸入&…

1.初識Linux

1.Linux 區分大小寫 2.shell命令行-bash 進入終端->[stulocalhost~]$ (其中,Stu為登錄用戶名&#xff0c;localhost為登錄主機名&#xff0c;’~’ 表示當前用戶正處在stu用戶的家目錄中, 普通用戶的提示符以$結尾&#xff0c;而根用戶以’#’結尾) 3.Linux中所謂的命令(…

這份NLP研究進展匯總請收好,GitHub連續3天最火的都是它

最近&#xff0c;有一份自然語言處理 (NLP) 進展合輯&#xff0c;一發布就受到了同性交友網站用戶的瘋狂標星&#xff0c;已經連續3天高居GitHub熱門榜首位。 合集里面包括&#xff0c;20多種NLP任務前赴后繼的研究成果&#xff0c;以及用到的數據集。 這是來自愛爾蘭的Sebasti…

基于模型的嵌入式開發流程_如何使用基于模型的測試來改善工作流程

基于模型的嵌入式開發流程Unit testing is not enough – so lets start using model-based testing to improve our workflows.單元測試還不夠–因此&#xff0c;讓我們開始使用基于模型的測試來改善我們的工作流程。 Software testing is an important phase in building a …

166. 分數到小數

166. 分數到小數 給定兩個整數&#xff0c;分別表示分數的分子 numerator 和分母 denominator&#xff0c;以 字符串形式返回小數 。 如果小數部分為循環小數&#xff0c;則將循環的部分括在括號內。 如果存在多個答案&#xff0c;只需返回 任意一個 。 對于所有給定的輸入…

最近用.NET實現DHT爬蟲,全.NET實現

最近用.NET實現DHT爬蟲&#xff0c;全.NET實現&#xff0c;大家可以加我QQ交流下 309159808 轉載于:https://www.cnblogs.com/oshoh/p/9236186.html

C++貪吃蛇

動畫鏈接 GitHub鏈接&#xff1a;https://github.com/yanpeng1314/Snake 1 #include "Snake.h"2 3 int iScore 0;4 int iGrade 1;5 6 //蛇頭蛇尾初始位置7 int x_head 1, y_head 3;8 int x_tail 1, y_tail 1;9 10 //地圖坐標11 int i_Map 1, j_Map 1;12 13 /…

遠程辦公招聘_招聘遠程人才時要尋找的5種技能

遠程辦公招聘Remote work is a fast emerging segment of the labor market. How to embrace this shift as an employer - and find, recruit, and empower remote staff - is a question many companies and hiring managers are grappling with.遠程工作是勞動力市場中快速崛…

10分鐘騰訊云配置免費https

騰訊云免費證書申請地址&#xff1a; https://console.cloud.tencent... 填寫相關信息 域名身份驗證 文件驗證 將fileauth.text 創建在網站訪問根目錄的 .well-known/pki-validation/目錄使得 www.**.com/.well-known/pki-validation/fileauth.text 能夠訪問詳情 等待5分鐘左右…

1588. 所有奇數長度子數組的和

1588. 所有奇數長度子數組的和 給你一個正整數數組 arr &#xff0c;請你計算所有可能的奇數長度子數組的和。 子數組 定義為原數組中的一個連續子序列。 請你返回 arr 中 所有奇數長度子數組的和 。 示例 1&#xff1a; 輸入&#xff1a;arr [1,4,2,5,3] 輸出&#xff1…

洛谷P3195 [HNOI2008]玩具裝箱TOY(單調隊列優化DP)

題目描述 P教授要去看奧運&#xff0c;但是他舍不下他的玩具&#xff0c;于是他決定把所有的玩具運到北京。他使用自己的壓縮器進行壓縮&#xff0c;其可以將任意物品變成一堆&#xff0c;再放到一種特殊的一維容器中。P教授有編號為1...N的N件玩具&#xff0c;第i件玩具經過壓…

680. 驗證回文字符串 Ⅱ

680. 驗證回文字符串 Ⅱ 給定一個非空字符串 s&#xff0c;最多刪除一個字符。判斷是否能成為回文字符串。 示例 1: 輸入: s “aba” 輸出: true 示例 2: 輸入: s “abca” 輸出: true 解釋: 你可以刪除c字符。 示例 3: 輸入: s “abc” 輸出: false 解題思路 使用…

Android--RxJava2更新體驗

截止日前最新版2017-3-15: RxJava compile ‘io.reactivex:rxjava:1.2.7’ compile ‘io.reactivex:rxandroid:1.2.1’ RxJava2 compile “io.reactivex.rxjava2:rxjava:2.0.7” compile “io.reactivex.rxjava2:rxandroid:2.0.1” 1:create操作改變 Rxjava CompositeSubscri…

kotlin和java語言_Kotlin VS Java – 2020年您應該學習哪種編程語言?

kotlin和java語言It has been several years since Kotlin came out, and it has been doing well. Since it was created specifically to replace Java, Kotlin has naturally been compared with Java in many respects.自Kotlin問世以來已經有好幾年了&#xff0c;而且一切…

oracle部署--安裝oracle軟件與部署單實例數據庫

一、安裝oracle數據庫軟件 1.創建相應的用戶組及用戶 groupadd oinstall groupadd oper groupadd dba useradd -g oinstall -G oper,dba oracle 2.創建oracle software安裝路徑 mkdir -p /u01/app/oracle/product/11.2.0/db_1 3.修改安裝路徑權限 chown -R oracle:oinstall …

web前端【第十一篇】jQuery屬性相關操作

知識點總結 1、屬性 屬性&#xff08;如果你的選擇器選出了多個對象&#xff0c;那么默認只會返回出第一個屬性&#xff09;、 attr(屬性名|屬性值) - 一個參數是獲取屬性的值&#xff0c;兩個參數是設置屬性值 - 點擊加載圖片示例 re…

528. 按權重隨機選擇

528. 按權重隨機選擇 給定一個正整數數組 w &#xff0c;其中 w[i] 代表下標 i 的權重&#xff08;下標從 0 開始&#xff09;&#xff0c;請寫一個函數 pickIndex &#xff0c;它可以隨機地獲取下標 i&#xff0c;選取下標 i 的概率與 w[i] 成正比。 例如&#xff0c;對于 w…