با سلام.
می خوام با انتخاب یک radio یک div نمایش داده شود و با انتخاب یک radio دیگر یک div دیگر نمایش داده شود.
کد زیر را نوشتم:
$(document).ready(function () { $("input[name$='toggler']").click(function () { var radio_value = $(this).val(); if (radio_value == '1') { $("#Student").show("slow"); $("#Teacher").hide(); } else if (radio_value == '2') { $("#Teacher").show("slow"); $("#Student").hide(); } }); });
این کد درست عمل می کنه اما مشکلم این است که هر وقت روی هر کدام کلیک شود صفحه به اول اسکرول می شود. اگر در وسط صفحه باشیم و یک radio را یزنیم صفحه با بالا اسکرول می شود.
لطفاً راهنمایی کنید
با تشکر
کد HTML را نیز قرار دهید
<div style="direction:rtl;margin-right:20px;" id="Teacher"> <form action="/Register/RegisterTeacher/" method="post" enctype="multipart/form-data"> @using CaptchaMvc.HtmlHelpers <div> @{ var caap = Html.MathCaptcha("تغییر کد", "کد امنیتی را وارد کنید"); } </div> @Html.ValidationMessage(cap.BuildInfo.InputElementId) <br /><br /> <div class="form-group"> <label for="exampleInputEmail1" style="font-size:20px;">نام</label> @Html.TextBoxFor(x => x.name, new { @class = "form-control", style = "text-align:right;width:400px;height:40px;float:right;" }) @Html.ValidationMessageFor(x => x.name, string.Empty, new { style = "margin-right:20px;float:right;font-weight:bold;" }) </div> <br /><br /><br /> <div class="form-group"> <label for="exampleInputEmail1" style="font-size:20px;">نام خانوادگی</label> @Html.TextBoxFor(x => x.Family, new { @class = "form-control", style = "text-align:right;width:400px;height:40px;float:right;" }) @Html.ValidationMessageFor(x => x.Family, string.Empty, new { style = "margin-right:20px;float:right;font-weight:bold;" }) </div> <br /><br /><br /> <div class="form-group"> <label for="exampleInputEmail1" style="font-size:20px;">شماره شناسنامه </label> @Html.TextBoxFor(x => x.ShSh, new { @class = "form-control", style = "text-align:right;width:400px;height:40px;float:right;" }) @Html.ValidationMessageFor(x => x.ShSh, string.Empty, new { style = "margin-right:20px;float:right;font-weight:bold;" }) </div> <br /><br /><br /> <div class="form-group"> <label for="exampleInputEmail1" style="font-size:20px;">شماره ملی </label> @Html.TextBoxFor(x => x.MelliCode, new { @class = "form-control", style = "text-align:right;width:400px;height:40px;float:right;" }) @Html.ValidationMessageFor(x => x.MelliCode, string.Empty, new { style = "margin-right:20px;float:right;font-weight:bold;" }) </div> <br /><br /><br /> <div class="form-group"> <label for="exampleInputEmail1" style="font-size:20px;">تلفن </label> @Html.TextBoxFor(x => x.Tell, new { @class = "form-control", style = "text-align:right;width:400px;height:40px;float:right;" }) @Html.ValidationMessageFor(x => x.Tell, string.Empty, new { style = "margin-right:20px;float:right;font-weight:bold;" }) </div> <br /><br /><br /> <div class="form-group"> <label for="exampleInputEmail1" style="font-size:20px;">شماره پرسنلی </label> @Html.TextBoxFor(x=>x.ShPersoneli, new { @class = "form-control", style = "text-align:right;width:400px;height:40px;float:right;" }) @Html.ValidationMessageFor(x => x.ShPersoneli, string.Empty, new { style = "margin-right:20px;float:right;font-weight:bold;" }) </div> <br /><br /><br /> <div class="form-group"> <label for="exampleInputEmail1" style="font-size:20px;">پست الکترونیک </label> @Html.TextBoxFor(x => x.Email, new { @class = "form-control", style = "text-align:right;width:400px;height:40px;float:right;" }) @Html.ValidationMessageFor(x => x.Email, string.Empty, new { style = "margin-right:20px;float:right;font-weight:bold;" }) </div> <br /><br /><br /> <div class="form-group"> <label for="exampleInputEmail1" style="font-size:20px;">تحصیلات </label> @Html.DropDownList("TahsilatID", (SelectList)TempData["Tahsilat"], "انتخاب", new { style = "width:400px;direction:rtl;height:40px;font-size:20px;float:right;" }) @*@Html.TextBoxFor(x => x.Email, new { @class = "form-control", style = "text-align:right;width:400px;height:40px;" }) @Html.ValidationMessageFor(x => x.Email, string.Empty, new { style = "margin-right:20px;float:right;" })*@ </div> <br /><br /><br /> <div class="form-group"> <label for="exampleInputEmail1" style="font-size:20px;">نوع معلم </label> @Html.DropDownList("TeacherTypeID", (SelectList)TempData["TeacherType"], "انتخاب", new { style = "width:400px;direction:rtl;height:40px;font-size:20px;float:right;" }) @*@Html.TextBoxFor(x => x.Email, new { @class = "form-control", style = "text-align:right;width:400px;height:40px;" }) @Html.ValidationMessageFor(x => x.Email, string.Empty, new { style = "margin-right:20px;float:right;" })*@ </div> <br /><br /><br /> <div class="form-group"> <label for="exampleInputEmail1" style="font-size:20px;">عکس </label> <input name="file1" value="" type="file" id="pimagefile" style="height:40px;font-size:20px;"> </div> <br /><br /><br /> <div class="form-group" style="height:270px;"> <label for="exampleInputEmail1" style="font-size:20px;">آدرس </label> @Html.TextAreaFor(x => x.Adress, new { @class = "form-control", style = "text-align:right;width:600px;height:240px;resize:none;float:right;" }) @Html.ValidationMessageFor(x => x.Email, string.Empty, new { style = "margin-right:20px;float:right;font-weight:bold;" }) </div> <br /><br /> <div dir="rtl"> @caap </div> <br /><br /> <!-- Provides extra visual weight and identifies the primary action in a set of buttons --> <button type="submit" class="btn btn-primary" style="width:100px;height:40px;">ثبت نام</button> </form> </div>
یک مشکل دیگه که برام پیش اومده اینه که DataAnnonation برای فیلد Name فقط روی Div با نام student اعمال می شود.
می خوام اگر Div با نام Student فعال بود و روی دکمه قبت نام کلیک شد Dataanonation برای تمام عناصر درون student عمل کند
و اگر div با نام teacher فعال بود و روی دکمه ثبت نام مربوط به آن کلیک شد Dataanonation روی عناصر teacher عمل کند.
با تشکر
هیچ کاربری تا کنون از این پست تشکر نکرده است
با ما تماس بگیرید تا در این مسیر همراهتان باشیم :)