Checkbox checked not work when using an hidden div
I have a dropdown (lbProperty), when the value selected value is 2, div1 is show but the 2 last line with textbox1 and textbox2 are hidden. It's ok that's work.
When div1 is show, there is no effect on the check event, I never see "Click!".
Any idea ?
Thanks,
In the main page :
@model DPI_MVC3Razor.Models.MyModel
$(document).ready(function () {
$('#div1').hide();
$('#lbProperty').change(function () {
var result = $(this).val();
$('#div1').hide();
if (result == 2)
$('#div1').show();
})开发者_如何学编程;
if ($('#checkbox1').attr('checked')) {
alert("Click!");
}
});
<div id="div1">
@Html.Partial("div1Content", Model)
</div>
In "div1Content"
@model DPI_MVC3Razor.Models.MyModel
<script type="text/javascript">
$(document).ready(function () {
$(".jcsss1").hide();
});
</script>
<table>
<tr>
<td>AAAAA</td>
<td>@Html.CheckBox("chk9", Model.IsOK)</td>
</tr>
<tr class="jcsss1">
<td>BBBBB</td>
<td>@Html.TextBox("textbox1", Model.MyValue1)</td>
</tr>
<tr class="jcsss1">
<td>CCCCC</td>
<td>@Html.TextBox("textbox2", Model.MyValue2)</td>
</tr>
</table>
You haven't placed anything on the check event.
if ($('#checkbox1').attr('checked')) {
alert("Click!");
}
this code is only within document.ready
, meaning it only executes once when the DOM finishes loading.
You want this:
$('#checkbox1').click(function(){
if ($(this).attr('checked')) {
alert("Click!");
}
});
精彩评论