我正在嘗試減少 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。
將 document.querySelector 或 document.querySelector
四季花海
2023-11-12 22:15:06