显示在j查询中无法正常工作的方法


Jquery:
$(document).ready(function(){
$(".li").click(function() {
//If a user leaves input fields empty and tries to log in this error will be shown
if ($("#username").val().length == "" || $("#password").val().length == "")
{$(".demo1").html("hello");}
});
});

Html:

<span class="demo"></span>
<a href="#" target="_self" class="li" id="lin">Log in</a>

单击时,文本出现并突然消失。我根本不希望文本消失。

它是创建问题的目标属性,每次单击都会重新加载页面本身,这会导致整个代码的刷新,因为由于$(document).ready(function(){});,一旦文档完成加载,jQuery代码就会运行。解决方案是删除目标属性或更改其值。

最新更新