0
希望我現在清楚我的問題。JavaScript代碼工作在窗體上加載
我有一個分享點列表,其中我隱藏/顯示基於另一個字段中數據的某些字段(是/否下拉列表)。舉例來說,我有第1列是和無下拉菜單。如果此列1中的值選擇爲Yes,則應顯示四列A,B,C和D.如果第1列爲否,則應隱藏A,B,C和D.它在表單加載時工作良好。
但是,當表單在保存時返回錯誤時,即使依賴字段仍然爲「是」,但在依賴字段中選擇「是」時顯示的字段將被隱藏,並且必須切換在是和否選擇之間再次顯示字段。
下面是我用過的代碼。
<script src="https://code.jquery.com/jquery-1.7.2.min.js" type=text/javascript></script>
<script type="text/javascript">
// Execute the following JavaScript after the page has fully loaded, when it's ".ready"
$(document).ready(function() {
$('nobr:contains("Question 1")').closest('tr').hide();
$('nobr:contains("Question 2")').closest('tr').hide();
$('nobr:contains("Question 3")').closest('tr').hide();
$('nobr:contains("Question 4")').closest('tr').hide();
//Show/hide columns based on Drop Down Selection
$("select[title='Do you know Java Scripting']").change(function() {
if ($("select[title='Do you know Java Scripting']").val() != "Yes") {
$('nobr:contains("Question 1")').closest('tr').hide();
$('nobr:contains("Question 2")').closest('tr').hide();
$('nobr:contains("Question 3")').closest('tr').hide();
$('nobr:contains("Question 4")').closest('tr').hide();
} else {
$('nobr:contains("Question 1")').closest('tr').show();
$('nobr:contains("Question 2")').closest('tr').show();
$('nobr:contains("Question 3")').closest('tr').show();
$('nobr:contains("Question 4")').closest('tr').show();
}
});
});
那麼你的代碼不會顯示驗證碼,所以很難幫助你。 – epascarello
感謝您的回覆epascarello。你能幫我解決嗎? –
我不能因爲我說的原因。你如何做驗證。 – epascarello