亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

將 document.querySelector 或 document.querySelector

將 document.querySelector 或 document.querySelector

四季花海 2023-11-12 22:15:06
我正在嘗試減少 jQuery 的使用,但有時我仍然需要使用 jQuery 中的方法。document.querySelector是否可以將或 的返回值轉換document.querySelectorAll為 jQuery 對象,或將 jQuery 選擇轉換為 document.querySelector() 或 document.querySelectorAll() 將返回的 Element 或 NodeList 對象?重新進行選擇似乎比使用已有的內容更昂貴。這是一個示例document.querySelector:let qsOutput = document.querySelector('#my_id');//now if I want to use jQuery's .attr (just as an example) qsOutput.attr("alt", "the new alt attribute");  //.attr() is a jquery function我該怎么做?我是否只需要再次選擇并浪費原始捕獲的資源?我不是問如何更改普通 JavaScript 中的屬性,我試圖減少 jQuery 的使用,但仍然需要時不時地使用它,但是當我已經有了一個 through 時,用它進行新的選擇似乎是document.querySelector這樣浪費。如果可能的話,我想重用返回document.querySelector并將其“升級”為jQuery。
查看完整描述

1 回答

?
慕森卡

TA貢獻1806條經驗 獲得超8個贊

您可以將一個或多個元素傳遞給 jQuery 函數。

$(qsOutput).attr("alt", "the new alt attribute");


查看完整回答
反對 回復 2023-11-12
  • 1 回答
  • 0 關注
  • 117 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號