我正在將CSS應用到一些元素,並讓它們顯示:無;並且每當用戶點擊一個單選按鈕時,它將顯示:無;關閉元素並顯示它。由jQuery格式化的CSS不應用於隱藏的元素?
但是,我通過jQuery將CSS應用於這些元素。每當頁面被加載時,寬度不被應用。我有setwidth(1/2)或其他東西,它會找到父div的寬度,將它剪成兩半,並將其設置爲該寬度。但是,因爲整個div顯示爲none,只要頁面加載,它甚至不會抓住jquery函數來做到這一點...所以寬度是0px ..每當我加載DIV,它..所有這些都是有效的,基本上只是一個巨大的0px寬度的DIV。
我該如何去做這件事?
好吧,我在哪裏,wifi作爲JFiddle過濾並阻止訪問它。 但這裏是我的標記:
HTML:
<fieldset id="new_item">
<legend>New Item</legend>
<div class="input-row">
<div class="input-wrap setwidth(1/2)">
@Html.LabelFor(model => model.ProductDescription, T("Product Description (maximum of 30 characters"))
@Html.TextBoxFor(model => model.ProductDescription, new { @class = "setwidth(1)", @maxlength = "30" })
</div>
<div class="input-wrap setwidth(1/2)">
@Html.LabelFor(model => model.ProductClass, T("Product Class"))
@Html.DropDownListFor(model => model.ProductClass, new System.Web.Mvc.SelectList(Model.ProductClasses, "Value", "Key"), new { @class = "setwidth(1)" })
</div>
</div>
還有更多,但後來這裏是我的jQuery和CSS:
<style type="text/css">
.hide { display: none; }
</style>
<script type="text/javascript">
$(document).ready(function() {
$('#new_item').addClass('hide');
$('#existing_item').addClass('hide');
$('#StateOfItem').change(function() {
//every time value of StateOfItem is changed
if ($('.new_item').is(':checked')) {
$('#new_item').removeClass('hide');
$('#existing_item').addClass('hide');
}
else if ($('.existing_item').is(':checked')) {
$('#new_item').addClass('hide');
$('#existing_item').removeClass('hide');
}
});
});
</script>
你能告訴我們相關的代碼和標記嗎? –
向我們展示您的代碼,HTML,CSS和jQuery。更好的是,製作一個jsFiddle – Lowkase
請包含一些代碼或JSFiddle鏈接。沒有代碼檢查/測試,幾乎不可能提供準確的答案。謝謝。 – TNCodeMonkey