2012-01-23 30 views
0

我在change_form.html中有許多字段集。基於點擊功能,我希望隱藏/顯示一些字段集。我如何獲取字段集ID?有超過1個字段集。如何在django的change_form.html中使用django jQuery查找字段集ID

In javascript eg。 $('fieldset')[1] .hidden = true; // false基於某些條件

我想要一個與上述語句相同的django jQuery。 $(「#fieldset」)1 = true;我試過,$(「#fieldset」)1 = true; 也試過$(「div.form-row.field1.field2」)。hidden = true;

我想只使用django.jQuery,如下所示。如何訪問fieldset 1,2和顯示/隱藏功能。

(function($){ 
    $(document).ready(function($){ 
//function to hide/show the fieldset related to POP3_status 
// if it is checked, show fieldset[1] and fieldset[2] 
//if it is not checked, hide fieldset[1], fieldset[2] 

    $("#id_pop3_status").click(function(){ 
     var checked = $("#id_pop3_status").is(':checked'); 

     //not a POP3 account 
     if (!checked){ 
     alert('not clicked'); 
       $("#fieldset")[1].hide(); 

     } 
     //if the POP3_status is checked i.e it is POP3 account 
     else { 
     alert('clicked'); 
       $("#fieldset")[1].show(); 
     } 
    }); 
    }); 
})(django.jQuery); 

回答

0

嘗試

$("#fieldset").hide(); 

如果你以後想表明它agian可以使用

$("#fieldset").show(); 
+0

我添加了類屬性,它可以與show/hide函數一起使用 – user956424

+0

好吧,將它標記爲已回答。 –

0

你倆嘗試過的事情是有效的jQuery:

$('fieldset')[1].hidden = true 

1)當你下標一個jQuery對象時t,你得到一個正常的JavaScript對象,所以你實際上需要做一些像$($('fieldset')[1])這樣的事情,把它變成一個jQuery對象。 2)hidden不是一個有效的屬性;您需要.hide()/.show()或類似.css('display', 'none')

$("div.form-row.field1.field2").hidden = True 

1)這實際上選擇div S作類「形式行」以及「字段1」 「場2」,這將不匹配任何東西。你在找什麼是$('div.form-row.field1, div.form-row.field2')。 2)關於hidden不是上述有效屬性的相同位應用

+0

我使用$(「.form-row.field1.field2」)。hide()或者顯示類,它工作正常 – user956424

相關問題