我有以下用於顯示/隱藏條件表單域(包含在tr#other-employer
內)的jQuery代碼。這工作正常,一旦頁面加載和選項更改。在加載時顯示一個條件表單域,當預先選擇時
我想這樣做,使得條件字段顯示何時加載頁面,並且在#employer
的下拉列表中選擇的選項被預先選擇(這是用PHP完成的)。
我試過刪除$('tr#other-employer').hide();
,但是這樣就顯示了加載條件字段,無論下拉字段是否是其他字段。
一個簡單的示例頁面在這裏:http://brenda.upreach.org.uk/beta/form.php
$(document).ready(function() {
$('tr#other-employer').hide();
$('#employer').change(function() {
if ($(this).val() == "Other") {
$('tr#other-employer').fadeIn();
} else {
$('tr#other-employer').hide();
}
});
});
任何幫助,不勝感激!
這正是我期待的!謝謝! – user2761030