带有 Jquery mobile 的 ListView 中的复选框 [英] Checkbox in ListView with Jquery mobile
问题描述
我开始学习 HTML5 和 CSS(使用 Jquery Mobile),因为我在这方面没有太多背景,所以我被困在一些非常简单的事情上.我想在列表视图中放置一个复选框(在每个 li 处).我该怎么做才能看起来像这样:http://a4.mzstatic.com/us/r1000/095/Purple/ff/1d/33/mzl.ecpvufek.320x480-75.jpg(我的意思是复选框位于其他文本和所有文本的左侧).
I am starting to learn HTML5 and CSS (with Jquery Mobile), and because I do not have much background in this area, I am stuck at something very easy. I want to put a checkbox in a listview (at each li). How can I do it in order to look like that : http://a4.mzstatic.com/us/r1000/095/Purple/ff/1d/33/mzl.ecpvufek.320x480-75.jpg (I mean that the checkbox is at the left of the others text and all).
目前,我的代码是:http://jsfiddle.net/AzN7S/正如您所看到的,复选框位于文本上方,即使在第二个 li 中有一个带有 float:left 的 div,它也不起作用:(
For the moment, my code is : http://jsfiddle.net/AzN7S/ And as you can see the checkbox is above the text, and even with a div with a float:left in the second li, it doesn't work :(
你能帮我吗?非常感谢您的回答,并为我的英语感到抱歉 ^^
Can you help me please ? Thank you very much beforehand for your answer, and sorry for my english ^^
祝您有美好的一天.
奥利维尔.
我终于成功在右侧部分的左侧添加了一个复选框.我更新了我的例子:http://jsfiddle.net/AzN7S/2/我不知道这是否是正确的方法,但它有效:)
I finally succeeded in adding a checkbox at the left of the the right part. I updated my example : http://jsfiddle.net/AzN7S/2/ I do not know if it is the right method, but it works :)
推荐答案
我重新思考了我的旧答案并重新解决了这个问题,特别是为了适应 mvc 4 框架,但客户端都是一样的.
那么让我们开始吧:
如果你只想要 html,你可以在这里得到它
这个链接是一个 3 部分的复选框列表,复选框,项目的链接和信息弹出:
i rethought my old answer and re did the issue especially to fit the mvc 4 framework but the client side is all the same.
so lets start:
if you just want the html you can get it here
this link is to a 3 parts checkbox list, the checkbox, the link to the item and the info popup:
iv 在最后添加了一些 2 部分列表框和一个部分,如有任何问题,请告诉我.
iv added at the end some 2 parts listbox and a single part, for any questions let me know.
现在对于控制器,您需要做的就是
now for the controller all you need to do is
[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 });
}
这是我的旧答案:
我解决了您的问题,您需要更改一些内容,但您可以使用复选框完成可搜索的列表视图,如下所示:
this was my old answer:
i solved your problem you need to change some stuff but you can accomplish a searchable listview with checkbox like so:
jsfiddle 示例:
jsfiddle example:
基本:基础jsfiddle版本
更好的版本:更好的版本
这篇关于带有 Jquery mobile 的 ListView 中的复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!