4 回答
TA贡献1155条经验 获得超0个赞
当您的页面加载时,仅加载您的电子邮件输入框.即:hide
//to hide email textbox on load
$('.emaillogin').css('display', 'none');
function showLogin(val) {
if (val == 1) {
$('.emaillogin').css('display', 'none');
$('.mobilelogin').css('display', '');
} else {
$('.mobilelogin').css('display', 'none');
$('.emaillogin').css('display', '');
}
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="radioBtns">
<label for='rbtnLoginTypeMobile'><input checked type="radio" id="rbtnLoginTypeMobile" name="rbtnLoginType" value='1' onclick="showLogin(1)"/><span>Mobile</span></label>
<label for='rbtnLoginTypeEmail'><input type="radio" id="rbtnLoginTypeEmail" name="rbtnLoginType" value='0' onclick="showLogin(0)" /><span>Email</span></label>
</div>
<div class="mobilelogin">
<div class="form-group">
<input type="number" id="mobilelogin" class="form-control form-control-user" name="mobilelogin" placeholder="<?php _e('Mobile') ?>">
</div>
</div>
<div class="emaillogin">
<div class="form-group">
<input type="Email" id="ُemaillogin" class="form-control form-control-user" name="emaillogin" placeholder="<?php _e('Email') ?>">
</div>
<div class="form-group">
<input type="number" id="ُemaillogin-ver-code" class="form-control form-control-user" name="emaillogin-ver-code" placeholder="<?php _e('Email Verification Code') ?>">
</div>
</div>
TA贡献1752条经验 获得超4个赞
您可以在窗口加载时调用相同的函数 showLogin。这是您可以处理此问题的方法之一。另一种方法可能是在同一脚本块中使用参数调用您的方法 showLogin()。请参阅下面的示例。
方法 1:
window.onload = function(){
showLogin(1)
}
方法 2:
<script type="text/javascript">
function showLogin(val) {
if (val == 1) {
$('.emaillogin').css('display', 'none');
$('.mobilelogin').css('display', '');
} else {
$('.mobilelogin').css('display', 'none');
$('.emaillogin').css('display', '');
}
}
showLogin(1)
</script>
TA贡献1824条经验 获得超6个赞
答案很有用,您也可以将移动登录类型的val设置为1,并将css设置为文档准备就绪,如下所示
<script type="text/javascript">
$(document).ready(()=>{
$('#rbtnLoginTypeMobile').val(1)
$('.emaillogin').css('display','none');
$('.mobilelogin').css('display','');
})
function showLogin(val)
{
if(val==1)
{
$('.emaillogin').css('display','none');
$('.mobilelogin').css('display','');
}
else
{
$('.mobilelogin').css('display','none');
$('.emaillogin').css('display','');
}
}
</script>
TA贡献1777条经验 获得超3个赞
获取 的值,然后以值作为参数进行调用。checked inputshowLogin
function showLogin(val) {
if (val == 1) {
$('.emaillogin').css('display', 'none');
$('.mobilelogin').css('display', '');
} else {
$('.mobilelogin').css('display', 'none');
$('.emaillogin').css('display', '');
}
}
const val = document.querySelector('input:checked').value;
if (val) {
showLogin(val);
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="radioBtns">
<label for='rbtnLoginTypeMobile'><input checked type="radio" id="rbtnLoginTypeMobile" name="rbtnLoginType"
value='1' onclick="showLogin(1)" /><span>Mobile</span></label>
<label for='rbtnLoginTypeEmail'><input type="radio" id="rbtnLoginTypeEmail" name="rbtnLoginType" value='0'
onclick="showLogin(0)" /><span>Email</span></label>
</div>
<div class="mobilelogin">
<div class="form-group">
<input type="number" id="mobilelogin" class="form-control form-control-user" name="mobilelogin" placeholder="<?php _e('Mobile') ?>">
</div>
</div>
<div class="emaillogin">
<div class="form-group">
<input type="Email" id="ُemaillogin" class="form-control form-control-user" name="emaillogin" placeholder="<?php _e('Email') ?>">
</div>
<div class="form-group">
<input type="number" id="ُemaillogin-ver-code" class="form-control form-control-user" name="emaillogin-ver-code" placeholder="<?php _e('Email Verification Code') ?>">
</div>
</div>
- 4 回答
- 0 关注
- 120 浏览
添加回答
举报