我想知道如何仅在特定功能中显示特定div。 我想显示以下div,称为" cd-popup"在我的javascript函数中调用" validateForm()"。
<script type="text/javascript">
function validateForm() {
var x = document.getElementById("email-id").value;
if ( x == null || x == "" ) {
$('.cd-popup').addClass('is-visible');
}
}
</script>
<div class="cd-popup" role="alert">
<div class="cd-popup-container" style="margin-left: 10%;">
<p style="color: #5b5b5b;">Are you sure you want to delete this element?</p>
<a href="#0" class="cd-popup-close img-replace">Close</a>
<!-- <img id="close" style="position: absolute;right: -14px;top: -14px; cursor: pointer;" onclick ="div_hide()"> -->
</div>
<!-- cd-popup-container -->
</div>
<!-- cd-popup -->
此外,我已进入电子邮件div,我通过&#34; onblur&#34;
打电话给该功能<!-- EMAIL -->
<div class="col-lg-6 col-xs-6">
<div class="form-group">
<input type="email" class="form form-control email requiretop" placeholder="Your email" name="email" id="email-id" onblur="return validateForm()">
</div>
</div>
我只想在调用validateForm()方法时显示div cd-popup
答案 0 :(得分:1)
这是一个简单的show-hide div现象,jQuery .show()和.hide()元素是这个的完美解决方案。只需按以下方式修改脚本:
<script type="text/javascript">
function validateForm() {
var x = document.getElementById("email-id").value;
if ( x == null || x == "" ) {
$('.cd-popup').show();
}
else{
$('.cd-popup').hide();
}
}
</script>