如何用jquery替换document.querySelector?

如何用jquery替换document.querySelector?,jquery,Jquery,我能代替我的工作 document.getElementById 与 其中homeStreets是字符串 po.homeStreets = 'table#home tr input[id^=home-street-]' 然而,当我试图做一个类似的行动来取代 po.home= 'table#home'; const table = document.querySelector(po.home); ^ ^ (哪个有效),有 我得到一个错误: t

我能代替我的工作

document.getElementById

其中
homeStreets
是字符串

po.homeStreets = 'table#home tr input[id^=home-street-]'
然而,当我试图做一个类似的行动来取代

po.home= 'table#home';
const table = document.querySelector(po.home);
                 ^         ^
(哪个有效),有

我得到一个错误:

table.insertRow is not a function

源HTML有3个id表,分别是
#home
#billing
#submit
当您使用jQuery选择一个元素时,它将返回一个封装在表单中的DOM元素

jQuery对象没有
insertRow
方法(属于)。你可以做:

const table = $(po.home)
const newRow = table[0].insertRow(skipFields + lastRowNum);

因为
.insertRow
不是jQuery方法(该方法会告诉您)->啊,是的,我忘记了,即使标识符只有1个匹配项,我仍然会得到一个数组,谢谢。不是吗?是的,很多次。我忘记了我正在重温的多元宇宙,抱歉。有用,谢谢。我更喜欢第一个是
consttable=$(po.home)[0]
你觉得怎么样?是的,它也会起作用。考虑到您正在使用jQuery,然后获取HTML元素。为什么不坚持一开始的代码呢?
table.insertRow is not a function
const table = $(po.home)
const newRow = table[0].insertRow(skipFields + lastRowNum);