我正在使用功能c_alert()
定製Jquery中的警報框。當用戶使用空登錄詳細信息登錄時,我顯示警告框。登錄時調用的函數如下所示。控制不返回到jQuery中的功能
function login()
{
var loginName = $("#US_UName").val();
var loginName = $.trim(loginName);
if (loginName == "") {
c_alert("Authentication Error","Please enter your username");
$("#US_UName").focus(); // not working
return false;
}
}
的c_alert()
是:
function c_alert(Title,Msg) {
$.confirm({
'title' : Title,
'message' : Msg,
'buttons' : {
'OK' : {
'class' : 'blue',
'action': function(){
return;
}
}
}
});
};
現在的問題是顯示警告後,我想指出光標到相應的字段進入細節,這是行不通的。我嘗試return;
在c_alert()
聲明,但沒有奏效。
爲$.confirm()
的代碼如下所示:
(function($){
$.confirm = function(params){
if($('#confirmOverlay').length){
// A confirm is already shown on the page:
return false;
}
var buttonHTML = '';
$.each(params.buttons,function(name,obj){
// Generating the markup for the buttons:
buttonHTML += '<a href="#" class="button '+obj['class']+'">'+name+'<span></span></a>';
if(!obj.action){
obj.action = function(){};
}
});
var markup = [
'<div id="confirmOverlay">',
'<div id="confirmBox">',
'<h1>',params.title,'</h1>',
'<p>',params.message,'</p>',
'<div id="confirmButtons">',
buttonHTML,
'</div></div></div>'
].join('');
$(markup).hide().appendTo('body').fadeIn();
var buttons = $('#confirmBox .button'),
i = 0;
$.each(params.buttons,function(name,obj){
buttons.eq(i++).click(function(){
// Calling the action attribute when a
// click occurs, and hiding the confirm.
obj.action();
$.confirm.hide();
return false;
});
});
}
$.confirm.hide = function(){
$('#confirmOverlay').fadeOut(function(){
$(this).remove();
});
}
})(jQuery);
誰能幫我找什麼,我做錯了什麼?
在此先感謝。
您聲明'VAR loginName'兩次!什麼是'.confirm'你做的一個插件,或者它的源代碼的鏈接在哪裏? – Sergio 2014-10-31 09:01:37