作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
如果您检查 radiobutton
之一,我在一个 View 中有两个表单只显示您想要的那个,问题是当您重新加载页面并且您没有检查任何单选按钮时显示您两种形式,我尝试输入 check
到其中一台 radio ,但不起作用,仍然显示两种形式,我该如何解决问题
radiobutton
的代码和 script
在 jQuery 中,当您选择一个时,它会显示您想要的表单代码radiobutton
<input type="radio" id="admin" value="administrador" name="tipo" >
<label for="admin">Admin</label>
<input type="radio" id="cliente" value="cliente" name="tipo">
<label for="natural">Cliente</label>
代码script
在 jQuery 中
<script type="text/javascript">
$(document).ready(function(){
$('input:radio[id=admin]').attr('checked',true);
$("#admin").on( "click", function() {
$('#email_1').show(); //muestro mediante id
$('#password_1').show();
$('#email_2').hide();
$('#password_2').hide();
});
$("#cliente").on( "click", function() {
$('#email_1').hide(); //oculto mediante id
$('#password_1').hide();
$('#email_2').show();
$('#password_2').show();
});
});
</script>
最佳答案
不要等待某人单击按钮来隐藏第二个表单,而是确保它在默认情况下以及单击单选按钮时隐藏。
<script type="text/javascript">
$(document).ready(function(){
$('input:radio[id=admin]').attr('checked',true);
$('#email_2').hide(); // Add this
$('#password_2').hide(); // and this
$("#admin").on( "click", function() {
$('#email_1').show(); //muestro mediante id
$('#password_1').show();
$('#email_2').hide();
$('#password_2').hide();
});
$("#cliente").on( "click", function() {
$('#email_1').hide(); //oculto mediante id
$('#password_1').hide();
$('#email_2').show();
$('#password_2').show();
});
});
</script>
关于javascript - 当我重新加载页面并且没有选中 Laravel 6.0 中的单选按钮之一时,如何一次只显示一个表单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59507876/
我是一名优秀的程序员,十分优秀!