带有Jquery移动设备的ListView中的复选框

时间:2012-06-27 12:11:17

标签: jquery-mobile

我开始学习HTML5和CSS(使用Jquery Mobile),因为我在这方面没有太多背景,所以我很容易陷入困境。 我想在列表视图中放置一个复选框(每个li)。 我该怎么做才能看起来像这样: http://a4.mzstatic.com/us/r1000/095/Purple/ff/1d/33/mzl.ecpvufek.320x480-75.jpg (我的意思是复选框位于其他文本的左侧,而且全部都是。)

目前,我的代码是:http://jsfiddle.net/AzN7S/ 正如您所看到的那样,复选框位于文本上方,即使是带有浮动的div:在第二个li中左侧,它也不起作用:(

你能帮帮我吗? 非常感谢您的回答,对不起我的英语^^

度过美好的一天。

奥利弗。

编辑:

我终于成功地在右侧部分的左侧添加了一个复选框。 我更新了我的示例:http://jsfiddle.net/AzN7S/2/ 我不知道它是否是正确的方法,但它有效:)

2 个答案:

答案 0 :(得分:12)

我重新考虑了我的旧答案并重新解决了问题,特别是为了适应mvc 4框架,但客户端却完全相同。
所以让我们开始:
如果你只是想要html,你可以在这里得到它 此链接指向3部分复选框列表,复选框,项目链接和信息弹出窗口:

Here is the link to jsfiddle for working listview with checkbox AND icon

iv最后添加了2个部分的列表框和单个部分,如有任何问题请告诉我。

现在对于控制器,你需要做的就是

[Authorize]
public ActionResult Items(string act, 
    string tab, string search_by, string search, string sort, string sortdir, int? page, int? resultsPerPage,
    List<int> selected, int? projectId, string username)
{
    if (act == "AddItemsToUser")
    {
        string response;
        if (selected != null)
        {
            response = "Project Items Added:";
            foreach (var item in selected)
            {
                try
                {
                    if (username != null)
                        if (UserItemRecordModel.InsertUserItem(username, item, null, null, 0, null, null))
                            response += item + " - inserted, ";
                }
                catch (Exception ex)
                {
                    response += item + " - " + ex.Message + ", ";
                }
            }
            response.TrimEnd(' ', ',');
        }
        else
        {
            response = "No Items Were Selected!";
        }
        return Json(response, JsonRequestBehavior.AllowGet);
    }
    else if (act == "AddItemsToProject")
    {
        string response;
        if (selected != null)
        {
            response = "Project Items Added:";
            foreach (var item in selected)
            {
                try
                {
                    if (projectId != null)
                        if (ProjectItemRecordModel.InsertProjectItem(projectId.ToString(), item, null, null, 0, null, null))
                            response += item + " - inserted, ";
                }
                catch (Exception ex)
                {
                    response += item + " - " + ex.Message + ", ";
                }
            }
            response.TrimEnd(' ', ',');
        }
        else
        {
            response = "No Items Were Selected!";
        }
        return Json(response, JsonRequestBehavior.AllowGet);
    }
    else if (act == "RemoveItemsFromUser")
    {
        string response;
        if (selected != null)
        {
            response = "Project Items Removed:";
            foreach (var item in selected)
            {
                try
                {
                    if (UserItemRecordModel.DeleteUserItem(username, item))
                        response += item + " - deleted, ";
                }
                catch (Exception ex)
                {
                    response += item + " - " + ex.Message + ", ";
                }
            }
            response.TrimEnd(' ', ',');
        }
        else
        {
            response = "No Items Were Selected!";
        }
        return Json(response, JsonRequestBehavior.AllowGet);
    }
    else if (act == "RemoveItemsFromProject")
    {
        string response;
        if (selected != null)
        {
            response = "Project Items Removed:";
            foreach (var item in selected)
            {
                if (ProjectItemRecordModel.DeleteProjectItem(projectId.ToString(), item))
                    response += item + " - deleted, ";
            }
            response.TrimEnd(' ', ',');
        }
        else
        {
            response = "No Items Were Selected!";
        }
        return Json(response, JsonRequestBehavior.AllowGet);
    }

    List<ItemRecordModel> items = ItemRecordModel.GetSensors(search_by, search, sort, sortdir);
    return View("Items", new AdminRecordsViewModel() { Records = items });
}

这是我的老答案:
我解决了你需要改变一些东西的问题,但你可以用复选框完成一个可搜索的列表视图:

jsfiddle例子:


碱性的: basic jsfiddle version

更好的版本: nicer version

jquery mobile listview with checkbox and icon or image

答案 1 :(得分:0)

here is a listView of checkBox and a search bar. you should add this js code 

 $("li").on("tap",function(){
                     $(this).find('label').click();
   });    in the button somewhere in your page.



the js code crete a click on the check box when the user clicks on the li

 <div class="ui-content" data-role="main">  
    <div data-role="main" class="ui-content">
         <h2 class="settings-h2">Select category</h2>
         <h5 lass="settings-h2">You will get articles on those subject,you can change your selection at any time.</h5>
        <form class="ui-filterable">
            <input id="myFilter-settings" data-type="search">
        </form>
         <ul data-role="listview" id="ScheduleList-settings" data-filter="true" data-input="#myFilter-settings"  data-inset="true" class="ui-listview ui-listview-inset ui-corner-all ui-shadow">



             <li  data-icon="false">
                 <form>
                <fieldset class="myhover" data-role="controlgroup" data-iconpos="right" >
                    <input type="checkbox" name="checkbox-h-6a" id="checkbox-Sports" >
                    <label  for="checkbox-Sports">Sports</label>
                </fieldset>
                </form>

            </li>


             <li data-icon="false" >


                 <form>
                <fieldset data-role="controlgroup" data-iconpos="right" >
                    <input type="checkbox" name="checkbox-h-6a" id="ccheckbox-Food" >
                    <label  for="ccheckbox-Food">Food</label>
                </fieldset>
                </form>


            </li>


             <li data-icon="false" >

                 <form>
                <fieldset data-role="controlgroup" data-iconpos="right" >
                    <input type="checkbox" name="checkbox-h-6a" id="checkbox-Politics" >
                    <label  for="checkbox-Politics">Politics </label>
                </fieldset>
                </form>


             </li>



             <li data-icon="false"  >

                 <form>
                <fieldset data-role="controlgroup" data-iconpos="right" >
                    <input type="checkbox" name="checkbox-h-6a" id="checkbox-Fashion" >
                    <label  for="checkbox-Fashion">Fashion</label>
                </fieldset>
                </form>


             </li>






            </ul>
     </div>

</div>