【问题标题】:jquery mobile checkbox and ASP .NETjquery 移动复选框和 ASP .NET
【发布时间】:2011-11-13 14:20:27
【问题描述】:

jquery mobile,form element-checkbox有问题。所以,我在 .cs 文件中有一个代码:

email = Request.Form["Email"];
password = Request.Form["password"];
rememberMe = Request.Form["remember_me"].AsBool();

通常,此代码必须用表单数据填充变量,但 jquery mobile 复选框的状态不使用“已检查”HTML 标记。 (http://jquerymobile.com/test/docs/forms/checkboxes/index.html)

它只是改变标签中的类,如“ui-checkbox-off/ui-checkbox-on”。

那么,是否可以在没有大量代码的情况下检查由 jquery mobile 创建的复选框的状态?

谢谢。

【问题讨论】:

  • 一个决定,可能带有隐藏的复选框,但这不是很好=\
  • jQueryMobile 文档说选中状态存储在 input[type=checkbox] 中。如果你看一看,你会发现这是真的。但是,将事件绑定到此类输入上的“更改”事件并不总是有效。

标签: javascript jquery asp.net .net jquery-mobile


【解决方案1】:

也许你可以做这样的事情?

<div data-role="fieldcontain" id="divCheckbox">
    <fieldset data-role="controlgroup">
       <legend>Agree to the terms:</legend>
       <input type="checkbox" name="checkbox-1" id="checkbox-1" class="custom" />
       <label for="checkbox-1">I agree</label>
    </fieldset>
</div>

JS

$("#divCheckbox").click(function() {

    var checkbox = $(this).find("input[type='checkbox']");

    var label = $(this).find(".ui-checkbox-on");

    checkbox.prop("checked", label.length);
});

不是 100% 确定,但至少 DOM 发生了变化(请参阅 http://jsfiddle.net/rcSza/4/)否则你可以用隐藏字段做一些事情..

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-08-25
    • 2010-11-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-23
    • 2016-09-23
    • 2016-12-14
    相关资源
    最近更新 更多