0

ラジオ ボタンの選択に基づいて、チェックボックス オプションのリスト全体を有効または無効にする必要があります。選択が無効化を要求するとき、私はこれを使用しています:

function radioSelectDNC() {
    for (i = 3; i < document.addPNtoDNC.elements.length - 1; i++) {
        document.addPNtoDNC[i].disabled=true;      // this is working
        document.addPNtoDNC[i].style.color="blue"; //this line is not working
    } 

無効化は機能しますが、チェックボックス オプションのテキストの色は機能しません。長い形式ですが、念のため、チェックボックスのオプションをリストする方法を次に示します。

            <label><input type="checkbox" name="Campaign" value="Value1">Value1<br></label>
            <label><input type="checkbox" name="Campaign" value="Value2">Value2<br></label>
            <label><input type="checkbox" name="Campaign" value="Value3">Value3<br></label>

正しいプロパティを使用していますか? プロパティのリストはどこにありますか?

念のため、jQuery を渡さないでください。私はこれを始めたばかりで、jQuery の回答を検索して見つけるたびに頭が回転し始めます。これらの日のいずれか。

4

2 に答える 2

1

I think you're making this harder on yourself than necessary. What you should do is create a CSS selector for a class and then apply that class when a checkbox is checked through simple javascript. Likewise you can also simply remove the class when the checkbox is unchecked. I know you asked for a non-JQuery solution so here take a look at this:

Change an element's class with JavaScript

This is how you would add and remove classes through pure Javascript. It doesn't look too bad, but definitely looks like a lot of trouble to simply do that right?

That's because it is and that's exactly why JQuery is so nice. I'm not gonna give you a JQuery answer because you said not to, but I'm still gonna recommend it. You can run away from JQuery for as long as you'd like, but if you take an hour of your time to learn JQuery or Prototype or whatever, you'll find you don't have to do so much work. JQuery has a nice toggleClass() function and it makes your life a lot easier. Hope this helps. If you need help, don't be afraid to ask. That includes learning JQuery.

于 2013-01-22T04:13:30.110 に答える
1

タグの色プロパティでは<input>なく、の色プロパティを変更しようとしているようです。<label>代わりに、ラベルを参照するようにパーツを変更するdocument.addPNtoDNC[i]必要があります (ここで何をしているのか正確にはわかりません)。document.addPNtoDNC[i].parentNode入力タグはラベルタグの内側にあるため、機能するはずです。

于 2013-01-22T03:50:00.043 に答える