0

我有这个<div>

<div id="category_choice"></div>

单击类别项目<div>时,它会附加一个

<div id="sports" class="category_item" onclick="addCategory('Sports/Health')">
    <div id="sports_thumb" class="category_thumb"></div>
    <p>Sports/Health</p>
</div>

在里面。现在,当我单击提交按钮时,它必须将“category_choice”中的“category_item”的 id 传递给 ajax。

我尝试使用以下代码执行此操作:

$(document).on('click','#nsubmit', function () {
    var category = $('#category_choice:first-child').attr('id');

Ajax... bla-bla-bla 数据:类别:类别...以及我没有提到的其他数据,因为它发送得很好。但是“类别”仍然是空的。请告诉我错误在哪里。

4

1 回答 1

4

可能是空间??

 $("#category_choice :first-child").attr('id') 

或者

正如@David在评论中提到的

$('#category_choice > :first')
于 2013-05-02T13:45:05.243 回答