我在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);
我添加了類屬性,它可以與show/hide函數一起使用 – user956424
好吧,將它標記爲已回答。 –