• 如何控制jquery ui弹窗下方按钮水平居中


    1、问题背景

         一般情况下,jquery ui弹窗下方的按钮是居右的,但是有时系统为了达到美观统一,需要将按钮放在中间


    2、问题原因

    <!DOCTYPE html>
    <html>
    	<head>
    		<meta charset="UTF-8">
    		<title>如何使jquery ui弹窗下方按钮水平居中</title>
    		<link rel="stylesheet" href="../js/jquery-ui-1.10.4/themes/base/jquery.ui.all.css">
    		<script src="../js/jquery-ui-1.10.4/jquery-1.10.2.js"></script>
    		<script src="../js/jquery-ui-1.10.4/ui/jquery-ui.js"></script>
    		<style>
    			.ui-progressbar {
    				height: 10px;
    			}
    			
    			#dialogFile {
    				min-height: 0px !important;
    			}
    		</style>
    		<script>
    			$(function() {
    				$("#dialogInfo").dialog({
    					resizable: false,
    					title: '新增',
    					height: 500,
    					 420,
    					modal: true,
    					buttons: {
    						"关闭": function() {
    							$(this).dialog("close");
    						}
    					}
    				});
    
    				$("#dialogFile").dialog({
    					autoOpen: false,
    					closeOnEscape: false,
    					resizable: false,
    					modal:true
    				});
    
    				$("#progressbar").progressbar({
    					value: false,
    					complete: function() {
    						$(".ui-dialog button").last().trigger("focus");
    					}
    				});
    			});
    
    			function openWin(obj) {
    				var fileUpload = $(obj).val();
    				checkFileSize(obj);
    				if(fileUpload) {
    					$("#dialogFile").prev().css("display","none");
    					$("#dialogFile").dialog("open");
    				}
    			}
    
    			function checkFileSize(obj) 
    			{
    				var filePath = $(obj).val();
    				var fileStart = filePath.lastIndexOf(".");
    				var endFile = filePath.substring(fileStart, filePath.length).toUpperCase();
    				if(endFile != ".PNG" && endFile != ".JPG" && endFile != ".GIF") 
    				{
    					hiAlert("文件限于png,jpg或gif格式");
    					return false;
    				}
    			
    				var img = new Image();
    				img.src = filePath;
    				if(img.fileSize > 0) 
    				{
    					if(img.fileSize > 20 * 1024 * 1024) 
    					{
    						hiAlert("上传的文件大小不能超过20M!");
    						return false;
    					}
    				}
    				return true;
    			}
    		</script>
    	</head>
    
    	<body>
    		<div id="dialogInfo" title="弹窗信息">
    			<input type="file" οnchange="openWin(this);" />
    		</div>
    
    		<div id="dialogFile" style="height:50px;290px;">
    			<div class="progress-label" style="100%;text-align:center;">正在上传...</div>
    			<div id="progressbar"></div>
    		</div>
    	</body>
    
    </html>


    3、解决办法

         需要添加样式

    <!DOCTYPE html>
    <html>
    	<head>
    		<meta charset="UTF-8">
    		<title>如何使jquery ui弹窗下方按钮水平居中</title>
    		<link rel="stylesheet" href="../js/jquery-ui-1.10.4/themes/base/jquery.ui.all.css">
    		<script src="../js/jquery-ui-1.10.4/jquery-1.10.2.js"></script>
    		<script src="../js/jquery-ui-1.10.4/ui/jquery-ui.js"></script>
    		<style>
    			.ui-progressbar {
    				height: 10px;
    			}
    			
    			#dialogFile {
    				min-height: 0px !important;
    			}
    			.ui-dialog .ui-dialog-buttonpane .ui-dialog-buttonset{
    				text-align: center;
    				float: none;
    			}
    		</style>
    		<script>
    			$(function() {
    				$("#dialogInfo").dialog({
    					resizable: false,
    					title: '新增',
    					height: 500,
    					 420,
    					modal: true,
    					buttons: {
    						"关闭": function() {
    							$(this).dialog("close");
    						}
    					}
    				});
    
    				$("#dialogFile").dialog({
    					autoOpen: false,
    					closeOnEscape: false,
    					resizable: false,
    					modal:true
    				});
    
    				$("#progressbar").progressbar({
    					value: false,
    					complete: function() {
    						$(".ui-dialog button").last().trigger("focus");
    					}
    				});
    			});
    
    			function openWin(obj) {
    				var fileUpload = $(obj).val();
    				checkFileSize(obj);
    				if(fileUpload) {
    					$("#dialogFile").prev().css("display","none");
    					$("#dialogFile").dialog("open");
    				}
    			}
    
    			function checkFileSize(obj) 
    			{
    				var filePath = $(obj).val();
    				var fileStart = filePath.lastIndexOf(".");
    				var endFile = filePath.substring(fileStart, filePath.length).toUpperCase();
    				if(endFile != ".PNG" && endFile != ".JPG" && endFile != ".GIF") 
    				{
    					hiAlert("文件限于png,jpg或gif格式");
    					return false;
    				}
    			
    				var img = new Image();
    				img.src = filePath;
    				if(img.fileSize > 0) 
    				{
    					if(img.fileSize > 20 * 1024 * 1024) 
    					{
    						hiAlert("上传的文件大小不能超过20M!");
    						return false;
    					}
    				}
    				return true;
    			}
    		</script>
    	</head>
    
    	<body>
    		<div id="dialogInfo" title="弹窗信息">
    			<input type="file" οnchange="openWin(this);" />
    		</div>
    
    		<div id="dialogFile" style="height:50px;290px;">
    			<div class="progress-label" style="100%;text-align:center;">正在上传...</div>
    			<div id="progressbar"></div>
    		</div>
    	</body>
    
    </html>
    .ui-dialog .ui-dialog-buttonpane .ui-dialog-buttonset{
    	text-align: center;
    	float: none;
    }




  • 相关阅读:
    mkconfig文件里的"cat << EOF >> config.h"
    (ARM v7)信号量、互斥体代码追踪
    (ARM v7)自旋锁、读写锁、顺序锁代码追踪
    mac 系统上安装navicat
    git2consul配置管理工具使用教程
    Spring Cloud Feign如何上传文件
    spring-cloud feign的多参数传递方案
    Consul下载安装及运行教程
    比SecureCRT更好用的工具MobaXterm下载安装使用教程
    Linux下RocketMQ下载安装教程
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13313840.html
Copyright © 2020-2023  润新知