我有一个登录弹出窗口,当没有会话弹出窗口出现,然后当我在写完user_id和密码后点击提交链接时,什么也没发生。但是当我第二次点击时一切正常。我认为它是关于页面加载但我不知道修复它。有谁有想法吗?感谢
编辑:当我输入错误的值时,我意识到了什么(data.tip ===' hata')它在第一次工作,但是当我输入正确的值时,我必须双击工作但我仍然无法处理它。
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.2.3/jquery.min.js"></script>
<script type="text/javascript" charset="utf-8">
$(document).ready(function(){
///////////////////////////////////General Popup
function launch()
{
$('#sign_up').lightbox_me({centered: true, onLoad: function() { $('#sign_up').find('input:first').focus()}});
}
$("#sign_up").lightbox_me({centered: true, preventScroll: true, onLoad: function() {
$("#sign_up").find("input:first").focus();
}});
$('table tr:nth-child(even)').addClass('stripe');
/////////////////////////////////////////// PopUp End
$("#log_in").click(function(e) // This is not working in first time
{
var kullanici_adi=$("#kullanici_adi").val();
var sifre=$("#sifre").val();
$.ajax
({
type: "POST",
url: "girisislemi.php",
data: {kullanici_adi : kullanici_adi,sifre:sifre},
dataType:"json",
success: function(data)
{
if(data.tip==='yonetici'||data.tip==='kullanici')
{
$("#log_in").addClass("close");
$ele.lightbox_me();
$ele.trigger('close');
}
if(data.tip==='hata')
{
$('input[type=text]').css( "border", "3px solid red" );
$('input[type=password]').css( "border", "3px solid red" );
}
}
});
e.preventDefault();
});
});
</script>
<link rel="stylesheet" href="styles.css" type="text/css" media="screen" title="no title" charset="utf-8">
</head>
<body>
<div id="sign_up">
<h3 id="see_id" class="" >Can I see some ID?</h3>
<span>Please sign in using the form below</span>
<div id="sign_up_form">
<label><strong>Username:</strong> <input type="text" id="kullanici_adi" class=""/></label>
<label><strong>Password:</strong> <input type="password" id="sifre" class="" /></label>
<div id="actions">
<a class="form_button " id="log_in" href="#">Sign in</a>
</div>
</div>
</div>
</body>
</html>
&#13;
答案 0 :(得分:0)
我在JSFiddle中尝试你的代码并且我有一个错误:$ ele变量未定义所以我在成功回调中添加了定义,如果你返回的json具有良好的tip属性,它第一次工作在我身边。
$(document).ready(function() {
///////////////////////////////////General Popup
function launch() {
$('#sign_up').lightbox_me({centered: true, onLoad: function() { $('#sign_up').find('input:first').focus()}});
}
$("#sign_up").lightbox_me({centered: true, preventScroll: true, onLoad: function() {
$("#sign_up").find("input:first").focus();
}});
$('table tr:nth-child(even)').addClass('stripe');
/////////////////////////////////////////// PopUp End
$("#log_in").click(function(e) { // This is not working in first time
var kullanici_adi=$("#kullanici_adi").val();
var sifre=$("#sifre").val();
$.ajax({
type: "POST",
url: "girisislemi.php",
data: {kullanici_adi: kullanici_adi, sifre: sifre},
dataType:"json",
success: function(data) {
// --- Some log to verify the content of data.tip
console.log(data.tip);
if(data.tip==='yonetici'||data.tip==='kullanici') {
$("#log_in").addClass("close");
// --- Here I define the $ele variable to use it after.
$ele = $('#sign_up');
$ele.lightbox_me();
$ele.trigger('close');
}
if(data.tip==='hata') {
$('input[type=text]').css( "border", "3px solid red" );
$('input[type=password]').css( "border", "3px solid red" );
}
}
});
e.preventDefault();
});
});