我在php文件裏有這段代碼。它應該根據特定參數顯示並隱藏一段html內容(我有一組複選框,如果你檢查它們,根據它的複選框顯示或隱藏一些內容)。這個javascript函數沒有定義?我該如何解決它?
現在,在我的樣式表出現許多錯誤之後,在剝離它之後,我仍然得到這個:firefox錯誤控制檯中的「隱藏未定義」(我已經嘗試了螢火蟲中的錯誤控制檯,並顯示沒有)。
這是代碼,我不知道如何隱藏,可以不定義:
$script =
$("input[id^=\'edit-field-tipos-unidades-disponible-value\']").change(function(){' .
$(".fila-matriz-gastos").hide();' .
$(".fila-matriz-gastos").prev("label").hide();' .
$("input[id^=\'edit-field-tipos-unidades-disponible-value\'][checked]").each(function(){' .
var tipo = $(this).val();' .
$(".tipo-uf-" + tipo).show();' .
$(".tipo-uf-" + tipo).prev().show();' .
$("input.tipo-uf-"+tipo+"[value=-1]").click(function(){' .
$("input.tipo-uf-" + tipo).attr("checked", $(this).attr("checked"));' .
});' .
});' .
}).change();';
I'm幾乎在這裏的損失,因爲我想主題的輸出,但我不不瞭解JavaScript的工作方式。
謝謝!
UPDATE:
這是隱藏或顯示輸出:
<fieldset class=" collapsible">
<legend>
<a href="#">Matriz de Gastos</a>
</legend>
<div>
<div class="form-item">
<label style="display: none;">
Gastos por
<em>Departamento</em>
:
</label>
<div class="form-checkboxes tipo-uf-131 fila-matriz-gastos hidden" style="display: none;">
<div id="edit-matriz-gastos-131--1-wrapper" class="form-item">
<label class="option" for="edit-matriz-gastos-131--1">
<input id="edit-matriz-gastos-131--1" class="form-checkbox tipo-uf-131 fila-matriz-gastos hidden" type="checkbox" value="-1" name="matriz_gastos[131][-1]" style="display: none;">
Seleccionar/deseleccionar todos
</label>
</div>
<div id="edit-matriz-gastos-131-108-wrapper" class="form-item">
<label class="checkbox" for="edit-matriz-gastos-131-108">
<input id="edit-matriz-gastos-131-108" class="form-checkbox tipo-uf-131 fila-matriz-gastos hidden" type="checkbox" value="108" name="matriz_gastos[131][108]">
Gas
</label>
</div>
這是被隱藏或顯示的東西複選框,按點擊與否:
經過:
<label style="display: block;"><label style="display: block;">
Gastos por
<em>Departamento</em>
:
</label>
<div class="form-checkboxes tipo-uf-131 fila-matriz-gastos hidden" style="display: block;">
未選中:
<label style="display: none;">
Gastos por
<em>Departamento</em>
:
</label>
<div class="form-checkboxes tipo-uf-131 fila-matriz-gastos hidden" style="display: none;">
和其他更新:
Here's什麼從來就發現在jQuery docs:
隱藏.hide()函數 - DOM操作
此功能隱藏匹配的元素在頁面上。它所做的是 將顯示配置設置爲「無」。你可以設置一個速度爲 消失'快','正常'或'慢'和一個回調函數 在影響被允許後執行。
例
$("#class_div").hide();
之前
<div id='class_div'>Hello world</div> <div id='class_div_2'>Hello world</div>
後:
<div id='class_div' style="display:none;">Hello world</div> <div id='class_div_2'>Hello world</div>
確認!我的眼睛 - 請爲了您自己的理智 - 使用[模板引擎],或者至少一些[heredoc](http://http://www.webresourcesdepot.com/19-promising-php-template-engines/) /www.tuxradar.com/practicalphp/2/6/3)! – JonnyReeves 2012-03-08 22:49:30
請顯示呈現的HTML/JS代碼... – powtac 2012-03-08 22:50:30
我很抱歉!我應該怎麼做才能使代碼更具可讀性?我不習慣編碼,也不知道heredoc,也不知道如何使用模板angines。這是一段不是我的代碼,我只是想了解它。 – Rosamunda 2012-03-08 23:09:36