-1

チェックボックスがチェックされていることに基づいて、「a.href」リンクを無効/有効にする必要があります。チェックボックスのリスト(2列)があります。「インストール」列の少なくとも 1 つのチェックボックスがオンになっている場合、「インストール」リンクが有効になり、それ以外の場合は無効になります。[削除] 列で少なくとも 1 つのチェックボックスがオンになっている場合、同じクラス名のリンクが有効になり、そうでない場合は無効になります。

私はこれを試しましたが、これが正しいかどうかわかりません。動作しません:

function refleshCheckboxes() {
    if ($("input:checked").length > 0) {
        $("input:checked").each(function(index, e) {
            var css = $(e).attr('class').split(' ').slice(-1);
            $("div.markActions a").each(function (index, e) {
                $(e).removeClass("disablelink").hasClass(css);
            });

        });
    }
    else {
        $("div.markActions a").addClass("disablelink");
    }
}

$("div.markActions a") - a.href リンクがある場所 (この div 内)

チェックボックスには、a.href リンクと同じクラス名があります。したがって、チェックボックスのクラス名を取得し、そのクラスを a.href リンクのクラスと一致させたいと考えています。

チェックボックス:

<input type="checkbox" value="2" class="checkbox install">

リンク:

<a class="iconDiskPlus install disablelink" href="#">Install</a>


ここに画像の説明を入力

4

3 に答える 3

1

私はそれを考え出した:

function refleshCheckboxes() {
    if ($("input.checkbox:checked").length > 0) {
        var arr = new Array(".install", ".uninstalled", ".enabled", ".disabled", ".download", ".remove");
        for (i = 0; i < arr.length; i++) {
            if ($("input.checkbox:checked").is(arr[i])) {
                $(".markActions a" + arr[i]).removeClass("disablelink");
            } else {
                $(".markActions a" + arr[i]).addClass("disablelink");
            }
        };
    }
    else {
        $("div.markActions a").addClass("disablelink");
    }
}
于 2012-11-06T08:56:54.390 に答える
0

以下のものを試してください。

</p>

$(function(){

    $('input.install').click(function(){ 

        var install_link =  $('a.install');
        if($('input.install:checked').length !=0){
        install_link.addClass('enablelink').text('install enabled');
        }
        else{
        install_link.addClass('disablelink').text('install disabled');                

        }                     
});         
});​

デモ用のjsフィドルをチェックしてください

于 2012-11-06T08:10:02.313 に答える
0

次のように onclick イベントをチェックボックスに設定できます。

<input id="someId" type="checkbox" value="2" class="checkbox install" onclick="myFunction()">

js ファイルで関数を定義します。

function myFunction(){
    var checkBox = document.getElementById("someId");
    if(checkBox.checked == true){
        //you have to give an id attribute to the object
        // which you want to hide
        var hideIt = document.getElementById("id");
        hideIt.style.visibility = "none";
    }
}
于 2012-11-06T08:11:14.667 に答える