我是否做过明显迟钝的事情,或者是否有一种特殊格式用于评估jqueryUI按钮回调中的if()
条件?
$(function(){
var focus_control = '';
$( '#alert' ).dialog({
autoOpen:false,
show: 'fade',
hide: 'fade',
buttons: {
Ok: function() {
$(this).dialog('close');
//Next line works if uncommented
//$('#username').focus();
//This if block breaks the js, but all works if this block commented out
//var focus_control assigned elsewhere (ajax)
if (focus_control=='staff_pick') {
$('#staff_pick').focus();
}else if {focus_control=='username') {
$('#username').focus();
}
}
}
});
});
有没有更好的方法来重写这个?我试过了:
if (focus_control!='') {
$('#%focus_control%').focus();
}