日期:2014-05-17  浏览次数:20375 次

Jqury单击每一行,动态获取选中的Value.

  <tr>
                <td class='title'>
                    <input type="checkbox" id="checkedId" name="checkedId" value="@Html.DisplayFor(modelItem => item.Id)"/>
                    <input type="hidden" id="GetTitleByCheckedId" name="GetTitleByCheckedId" value=""/>                  
                    @Html.DisplayFor(modelItem => item.Title)
                </td>
 </tr>

   $('.title').click(function () {//文章标题
        alert($(this).text());
        sleTitle += "," + $(this).text();
        sleTitle = sleTitle.substring(1);
        alert(sleTitle);
        $("#GetTitleByCheckedId").val(sleTitle);
        //sleTitle = $(this).text();
    })


单击每一行出现的问题:
 1.获取到字符串是  sleTitle=   43T, 45, , , ,
 2.希望获取到的是  sleTitle=43T,45


jqury mvc

------解决方案--------------------
if($(this).text()!=""){sleTitle += $(this).text()+"," ;}
------解决方案--------------------
判断一下不行吗
var txt = $(this).text();
if(txt != ""){
    sleTitle += "," + $(this).text();
    sleTitle = sleTitle.substring(1);
}
------解决方案--------------------
引用:

  <tr>
                <td class='title'>
                    <input type="checkbox" id="checkedId" name="checkedId" value="@Html.DisplayFor(modelItem => item.Id)"/>
                    <input type="hidden" id="GetTitleByCheckedId" name="GetTitleByCheckedId" value=""/>                  
    &nbs