Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
在使用 jQuery时,我似乎很难记住何时使用<element>(带括号)和何时使用(不带括号)。element例如比较从 a 中添加然后删除optiona select:
<element>
element
option
select
$("#items").append( $('<option>', {value:"third", text:"Third"}) ); $("#items").find('option').remove();
该append方法需要括号,而该find方法不需要。如何调和这种不一致?
append
find
谢谢。
创建新元素时使用方括号,就像编写 HTML 时使用方括号一样。
选择现有元素时不要使用方括号,就像在 CSS 中选择元素时不使用方括号一样。