【问题标题】:When checkbox checked in list item, only enable textboxes in that list item - by class Jquery在列表项中选中复选框时,仅启用该列表项中的文本框 - 按 Jquery 类
【发布时间】:2013-10-04 08:22:27
【问题描述】:

我有一个项目列表,我需要做的是能够选中该列表项中的复选框,然后才启用该列表项中的复选框。这是我到目前为止所做的JSFiddle。这将启用页面上具有该类名称的所有复选框。由于这来自数据源是一个 JS 文件,这些列表项是在剑道模板中生成的,所以我需要带有类名的文本框。

谢谢

<ul id="productsFoundList" data-role="listview" data-style="inset" class="km-list" data-bind="source:foundProducts" data-template="productsFound-listview-filtering-template">
<li>
    <label>code - desc
        <input type="checkbox" name="eventActionToBeTaken" class="productsUl" />
        <div style="position: relative; padding-top:18px; padding-bottom:15px">
            <div style="margin-left:80px">
                <label style="color:grey">Qty</label>
                <input type="number" value="" class="productsFoundInputBorders" style="margin-right:40px" disabled/>
                <label style="color:grey">Price</label>
                <input type="number" value="" class="productsFoundInputBorders" style="margin-right:40px" disabled/>
                <label style="color:grey">Discount(%)</label>
                <input type="number" value="" class="productsFoundInputBorders" disabled/>
            </div>
            <div style="padding-top:5px; ">
                <label style="color:grey; margin-left:64px">Notes</label>
                <input class="productsFoundInputBorders" type="text" style="width:530px !important;" value="" disabled/>
            </div>
        </div>
    </label>
</li>
<li>
    <label>code - desc
        <input type="checkbox" name="eventActionToBeTaken" class="productsUl" />
        <div style="position: relative; padding-top:18px; padding-bottom:15px">
            <div style="margin-left:80px">
                <label style="color:grey">Qty</label>
                <input type="number" value="" class="productsFoundInputBorders" style="margin-right:40px" disabled/>
                <label style="color:grey">Price</label>
                <input type="number" value="" class="productsFoundInputBorders" style="margin-right:40px" disabled/>
                <label style="color:grey">Discount(%)</label>
                <input type="number" value="" class="productsFoundInputBorders" disabled/>
            </div>
            <div style="padding-top:5px; ">
                <label style="color:grey; margin-left:64px">Notes</label>
                <input class="productsFoundInputBorders" type="text" style="width:530px !important;" value="" disabled/>
            </div>
        </div>
    </label>
</li>

         $("#productsFoundList").click(function() { //when list click
        $(".productsUl").each(function() { //for each checkbox
            if($(this).is(":checked") == true)
            {
                $("#basketButton").show(500);
            }
        });

        if($('.productsUl:checked').length == 0)
        {
            $("#basketButton").hide(500);
        }
    });

    $("#productsFoundList").click(function() {
        if ($(".productsUl").is(":checked") == true) {
            $(".productsFoundInputBorders").prop('disabled', false);
        }
        else
        {
            $(".productsFoundInputBorders").prop('disabled', true);
        }
    });

【问题讨论】:

  • 你的小提琴什么都没有

标签: jquery html list kendo-mobile


【解决方案1】:

试试

var $basket = $("#basketButton");
var $checks = $(".productsUl").change(function () { //for each checkbox
    $(this).next().find(".productsFoundInputBorders").prop('disabled', !this.checked);
    $basket.stop(true, true)[$checks.filter(':checked').length  == 0 ? 'hide' : 'show'](500)
});

演示:Fiddle

【讨论】:

  • 谢谢!!!我必须在您的代码之前添加 $("#productsFoundList").click(function() { 但它当时有效!
  • 我确实注意到关闭时的#basket 按钮不像以前那样隐藏,我需要隐藏的外观,我该怎么做?
  • 按钮功能再次起作用,但现在不是复选框之一,感谢您当时的所有帮助
  • 从头开始,添加 $("#productsFoundList").click(function() { 再次
猜你喜欢
  • 2014-06-08
  • 2021-10-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多