zoukankan      html  css  js  c++  java
  • 如何控制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;
    }




  • 相关阅读:
    nginx过一段时间出现400 Bad Request 错误的解决方法
    log4j.properties的配置详解
    新手指南:Linux上vi(vim)编辑器使用教程
    JDK1.6在LINUX下的安装配置[转]
    Oracle中查看所有表和字段以及表注释.字段注释
    mybatis中使用in查询时的注意事项
    启动64位 IIS 32位应用程序的支持
    tar 打包命令
    类型强转和字节对齐
    emacs windows 下配置
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13313840.html
Copyright © 2011-2022 走看看