0
當您正在創建新頁面時,此代碼正常工作。選擇下拉菜單將顯示或隱藏標記所修飾的內容。問題出在一個編輯頁面,默認選中Id,比如Id 3我想用3裝飾的div在頁面加載時隱藏。我完全用javascript和jquery在海上。根據所選下拉菜單隱藏div
<div class="form-group">
<label class="control-label col-md-2" for="ArticleCategoryId">Menu Category</label>
<div class="col-md-10">
<select class="chooseOption form-control" id="ArticleCategoryId" name="ArticleCategoryId">
<option value="1">pages</option>
<option value="2">about</option>
<option selected="selected" value="3">project</option>
<option value="4">gallery</option>
<option value="5">news</option>
<option value="6">events</option>
<option value="7">FAQS</option>
<option value="8">Jobs</option>
<option value="9">Documents</option>
<option value="10">Clients</option>
</select>
<div class="form-group ArticleCategoryId 3">
<label class="control-label col-md-2" for="ArticleOnDate">Start Date</label>
<div class="col-md-10">
<input class="form-control text-box single-line" data-val="true" data-val-date="The field Start Date must be a date." id="ArticleOnDate" name="ArticleOnDate" type="datetime" value="" />
<span class="field-validation-valid text-danger" data-valmsg-for="ArticleOnDate" data-valmsg-replace="true"></span>
</div>
</div>
<div class="form-group ArticleCategoryId 1">
<label class="control-label col-md-2" for="ArtilceOnTime">On Time</label>
<div class="col-md-10">
<input class="form-control text-box single-line" id="ArtilceOnTime" name="ArtilceOnTime" type="text" value="" />
<span class="field-validation-valid text-danger" data-valmsg-for="ArtilceOnTime" data-valmsg-replace="true"></span>
</div>
</div>
下面是jQuery的片段
<script type="text/javascript">
jQuery(".optionName").hide();
jQuery("document").ready(function() { /// have to wait till after the document loads to run these things
jQuery("select.chooseOption").change(function() {
jQuery("." + this.id).hide();
var thisValue = jQuery(this).val();
if (thisValue != "")
jQuery("." + thisValue).show();
});
});
</script>
這是一個編輯的網頁我想"<div class="form-group ArticleCategoryId 3">....</div>
要在頁面加載隱藏因爲項目編號3已經被選擇,但其他應顯示。任何幫助將不勝感激
謝謝,我不知道,但我的代碼我可以只添加多個ID他們都會迴應像ArticleCategoryId 1 3 4 5我想知道如果你的代碼會使這個可能我只是試過1 2,它是壞的 – Diin