JQuery移动单选按钮在选择其他按钮时保持选中状态.使用.html函数
JQuery Mobile Radio Buttons stay selected when selecting other buttons. Using .html function
我似乎弄不清楚,也找不到任何有关这方面的信息。我使用. HTML()函数生成动态HTML,以单选按钮格式列出相机选择。创建html的代码工作正常,AFAIK:
var showcameras = function()
{
var html = "<fieldset data-role='controlgroup' data-type='horizontal'>";
for (var i = 0; i < sessiondetails["Camera-Count"]; i++)
{
var name;
var namelabel = "Camera-Names_" + i;
var idlabel = "Camera-ID_" + i;
if (sessiondetails[namelabel]==="")
name = "Camera " + (i+1);
else
name = sessiondetails[namelabel];
html += "<input type='radio' name='"+name+"' id='"+sessiondetails[idlabel]+"' value='"+sessiondetails[idlabel]+"'>";
html += "<label for='"+sessiondetails[idlabel]+"'>"+name+"</label>";
}
html += "</fieldset>";
window.$("#camselection").html(html).trigger("create");
};
它创建的HTML:
<fieldset data-role='controlgroup' data-type='horizontal'>
<input type='radio' name='test1' id='10000' value='10000'>
<label for='10000'>test1</label>
<input type='radio' name='Camera 2' id='10001' value='10001'>
<label for='10001'>Camera 2</label>
<input type='radio' name='Camera 3' id='10002' value='10002'>
<label for='10002'>Camera 3</label>
<input type='radio' name='Camera 4' id='10003' value='10003'>
<label for='10003'>Camera 4</label>
</fieldset>
这是"camselection"div标签的HTML:
<div id="camselection" data-role="fieldcontain"></div>
问题来了,我一次可以选择多个单选按钮。对我来说没有意义,因为它们在同一个字段集中。我甚至试过把onClick("刷新")放在每个按钮上,但它不起作用。任何帮助都非常感谢!
为了只选择一个单选按钮,它们必须具有相同的名称。
<fieldset data-role='controlgroup' data-type='horizontal'>
<input type='radio' name='camera' id='c10000' value='10000'>
<label for='c10000'>test1</label>
<input type='radio' name='camera' id='c10001' value='10001'>
<label for='c10001'>Camera 2</label>
<input type='radio' name='camera' id='c10002' value='10002'>
<label for='c10002'>Camera 3</label>
<input type='radio' name='camera' id='c10003' value='10003'>
<label for='c10003'>Camera 4</label>
</fieldset>
id
属性以字母开头时效果更好。http://www.w3schools.com/html/html_forms.asp
单选按钮分组由name属性定义。你的按钮都有不同的名字,所以它们是不同组的一部分。
应该是这样的:
<fieldset data-role='controlgroup' data-type='horizontal'>
<input type='radio' name='camera' id='10000' value='10000'>
<label for='10000'>test1</label>
<input type='radio' name='camera' id='10001' value='10001'>
<label for='10001'>Camera 2</label>
<input type='radio' name='camera' id='10002' value='10002'>
<label for='10002'>Camera 3</label>
<input type='radio' name='camera' id='10003' value='10003'>
<label for='10003'>Camera 4</label>
</fieldset>
尝试给单选按钮相同的名称。然后,您将只能选择一个单选按钮。
相关文章:
- 如何使用密码检测网络中的状态连接
- 使用javascript反复检查用户在facebook上的登录状态
- 无法在现有状态转换期间更新-未使用任何非法的setState()
- 使用AngularJS中的UI路由器将状态重定向到默认子状态
- 为什么使用immutableJS我的状态没有改变
- 使用纯javascript而非jquery使所选选项卡处于活动状态并保持非活动状态
- 使用按钮和媒体查询切换显示状态
- 使用api在facebook页面上发布图片或状态
- ReactJS:使用浏览器按钮导航时保存状态
- 在通知点击时使用Ion中的OneSignal插件路由到应用程序中的状态
- 如何使用sendy检查用户(已订阅或未订阅)的状态
- AngularJS&Google可视化-使用状态更改处理程序(Google API)在HTML页面上查看$sco
- 使用PHP或Javascript获取服务器状态
- 使用Re-base时,在React中从状态绑定和取消绑定Firebase
- 如果我不应该在组件WillUpdate中调用setState,如何更新状态(使用ReactJS)
- 跨页面记住 DIV 状态.使用 cookie 或哈希
- JQuery移动单选按钮在选择其他按钮时保持选中状态.使用.html函数
- Ui-router惰性加载状态使用url
- 错误状态:使用angular js和codeigniter 2.2
- 显示链接到我的最新推文的状态使用jQuery &如何执行它