聘我网

新概念招聘3.0

jQuery选择子问题

vote up0vote downstar

从firebug:

>>> $("form#commentform").serialize();
"username=&email=&comment=&verify="
>>> $("#commentform").serialize();
""
>>> $("form#commentform")
[form#commentform]
>>> $("#commentform")
[div#commentform]
>>> $("#commentform").length
1

为何form#commentform结果正常,而#commentform就不正常?

 

1 个答复

vote up0vote downcheck

页面中有两个元素的idcommentform,而$('#commentform')仅仅返回第一个,不是form,无法执行serialize()操作.

$("#commentform").length返回1是因为它采用的api是getElementById,只返回一个

详见说明

Matches a single element with the given id attribute.

链接

您的回答





不是您要找的问题? 浏览其他含有标签 的问题或者 自己问个.