简体   繁体   English

禁用复选框上的文本框

[英]Disable textbox on checkbox checked

I'm trying to disable an input field when a checkbox is (not) checked. 我正在尝试在未选中复选框的情况下禁用输入字段。
I know that there are already answers to this question but what they said didn't seem to work for me. 我知道这个问题已经有了答案,但他们所说的似乎对我没用。
So what i tried was this: 所以我尝试的是:

function disableWarentarifByAusland() {
var isChecked = $("#ausland").is(":checked");
var warentarif = $("#ArtikelTabelle .warentarif");
alert(warentarif);
for (var ii = 0; warentarif.length >= ii  ; ii++) {
    if (!isChecked) {
        $(warentarif[ii]).prop("disbled", true);
        //$(warentarif[ii]).val(true);
    } else {
        $(warentarif[ii]).prop("disbled", false);
        //$(warentarif[ii]).val(false);
    }
}
}

Using it on this table: 在此表上使用它:

   $("#add_row").click(function () {
    lZeile++;
    $("#ArtikelTabelle > tbody").append('<tr id="reihe' + lZeile + '">' +
        '<td rowspan="2"><b>' + (lZeile + 1) + '</b></td>' +
        '<td><input class="form-control" id="ccTabelle_' + lZeile + '__ccArtikelNr" name="ccTabelle[' + lZeile + '].ccArtikelNr" type="text" value="" placeholder="Artikelnummer"/></td>' +
        '<td><input class="form-control warentarif" data-val="true" data-val-required="Das Feld &quot;Warentarif-Nr&quot; ist erforderlich." id="ccTabelle_' + lZeile + '__ccWarentarifNr anzahl" name="ccTabelle[' + lZeile + '].ccWarentarifNr" type="text" value="" placeholder="Warentarifnummer"/></td>' +
        '<td><input class="form-control anzahl" data-val="true" data-val-number="Das Feld &quot;Anzahl&quot; muss eine Zahl sein." data-val-required="Das Feld &quot;Anzahl&quot; ist erforderlich." id="ccTabelle_' + lZeile + '__ccAnzahl" name="ccTabelle[' + lZeile + '].ccAnzahl" type="text" placeholder="Anzahl" /></td>' +
        '<td><input class="form-control preis" data-val="true" data-val-number="Das Feld &quot;Einzelpreis&quot; muss eine Zahl sein." data-val-required="Das Feld &quot;Einzelpreis&quot; ist erforderlich." id="ccTabelle_' + lZeile + '__ccEinzelpreis" name="ccTabelle[' + lZeile + '].ccEinzelpreis" type="text" placeholder="Einzelpreis"/></td>' +
        '<td rowspan="2"><a class="btn btn-default delete_row" data-rowid="' + lZeile + '">Artikel löschen</a></td>' +
        '</tr>' +
        '<tr id="text' + lZeile + '">' +
        '<td colspan="4"><textarea class="form-control" data-val="true" data-val-required="Das Feld &quot;Inhaltsbeschreibung&quot; ist erforderlich." id="ccTabelle_' + lZeile + '__ccInhaltsbeschreibung" name="ccTabelle[' + lZeile + '].ccInhaltsbeschreibung" placeholder="Inhalt">' +
        '</textarea></td></tr>');

I'm using the content of the append to create the table on document ready. 我正在使用附加内容在准备好文档的表格上创建表格。
You can see in the jquery that I used alert() and val() to test if this function is executed and it does. 您可以在jquery中看到我使用alert()val()来测试此函数是否执行以及是否执行。 I can change the content in the input field and the alert goes off, but the prop doesn't change or even appear in the code, after checking. 我可以在输入字段中更改内容,并且警报会关闭,但是检查后道具不会更改,甚至不会出现在代码中。
What is my problem here ? 我这是什么问题?

You should fix the spelling of you ' disabled ' property name: 您应该修复“ 禁用 ”属性名称的拼写:

$(warentarif[ii]).prop("disabled", true);

$(warentarif[ii]).prop("disabled", false);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM