js 弹出一个选择下拉框

来源:互联网 发布:godaddy 阿里域名 编辑:程序博客网 时间:2024/06/05 16:30

代码来自赖人建站,修改了部分js

html  

<html xmlns="http://www.w3.org/1999/xhtml"><head><title>jQuery的各种提示框参考 - 懒人建站</title><meta http-equiv="Content-Type" content="text/html; charset=gb2312"><script src="js/jquery.js" type="text/javascript"></script><script src="js/jquery.alerts.js" type="text/javascript"></script><link media="screen" href="js/jquery.alerts.css" type="text/css" rel="stylesheet"><script type="text/javascript">$(document).ready( function() {$("#prompt_button").click( function() {jSelect('请选择:',{'1':'张三','2':'李四'}, '人物', function(inputdata) {alert(inputdata);});});});</script></head><body screen_capture_injected="true"><input id="prompt_button" type="button" value="选择按钮"></body></html>

jquery.alerts.js

(function($) {$.alerts = {// These properties can be read/written by accessing $.alerts.propertyName from your scripts at any timeverticalOffset: -75,                // vertical offset of the dialog from center screen, in pixelshorizontalOffset: 0,                // horizontal offset of the dialog from center screen, in pixels/repositionOnResize: true,           // re-centers the dialog on window resizeoverlayOpacity: .01,                // transparency level of overlayoverlayColor: '#FFF',               // base color of overlaydraggable: true,                    // make the dialogs draggable (requires UI Draggables plugin)okButton: ' OK ',         // text for the OK buttoncancelButton: ' Cancel ', // text for the Cancel buttondialogClass: null,                  // if specified, this class will be applied to all dialogs// Public methodsalert: function(message, title, callback) {if( title == null ) title = 'Alert';$.alerts._show(title, message, null, 'alert', function(result) {if( callback ) callback(result);});},confirm: function(message, title, callback) {if( title == null ) title = 'Confirm';$.alerts._show(title, message, null, 'confirm', function(result) {if( callback ) callback(result);});},prompt: function(message, value, title, callback) {if( title == null ) title = 'Prompt';$.alerts._show(title, message, value, 'prompt', function(result) {if( callback ) callback(result);});},select: function(message, value, title, callback) {if( title == null ) title = 'Select';$.alerts._show(title, message, value, 'select', function(result) {if( callback ) callback(result);});},// Private methods_show: function(title, msg, value, type, callback) {$.alerts._hide();$.alerts._overlay('show');$("BODY").append(  '<div id="popup_container">' +    '<h1 id="popup_title"></h1>' +    '<div id="popup_content">' +      '<div id="popup_message"></div>' +'</div>' +  '</div>');if( $.alerts.dialogClass ) $("#popup_container").addClass($.alerts.dialogClass);// IE6 Fixvar pos = ($.browser.msie && parseInt($.browser.version) <= 6 ) ? 'absolute' : 'fixed'; $("#popup_container").css({position: pos,zIndex: 99999,padding: 0,margin: 0});$("#popup_title").text(title);$("#popup_content").addClass(type);$("#popup_message").text(msg);$("#popup_message").html( $("#popup_message").text().replace(/\n/g, '<br />') );$("#popup_container").css({minWidth: $("#popup_container").outerWidth(),maxWidth: $("#popup_container").outerWidth()});$.alerts._reposition();$.alerts._maintainPosition(true);switch( type ) {case 'alert':$("#popup_message").after('<div id="popup_panel"><input type="button" value="' + $.alerts.okButton + '" id="popup_ok" /></div>');$("#popup_ok").click( function() {$.alerts._hide();callback(true);});$("#popup_ok").focus().keypress( function(e) {if( e.keyCode == 13 || e.keyCode == 27 ) $("#popup_ok").trigger('click');});break;case 'confirm':$("#popup_message").after('<div id="popup_panel"><input type="button" value="' + $.alerts.okButton + '" id="popup_ok" /> <input type="button" value="' + $.alerts.cancelButton + '" id="popup_cancel" /></div>');$("#popup_ok").click( function() {$.alerts._hide();if( callback ) callback(true);});$("#popup_cancel").click( function() {$.alerts._hide();if( callback ) callback(false);});$("#popup_ok").focus();$("#popup_ok, #popup_cancel").keypress( function(e) {if( e.keyCode == 13 ) $("#popup_ok").trigger('click');if( e.keyCode == 27 ) $("#popup_cancel").trigger('click');});break;case 'prompt':$("#popup_message").append('<br /><input type="text" size="30" id="popup_prompt" />').after('<div id="popup_panel"><input type="button" value="' + $.alerts.okButton + '" id="popup_ok" /> <input type="button" value="' + $.alerts.cancelButton + '" id="popup_cancel" /></div>');$("#popup_prompt").width( $("#popup_message").width() );$("#popup_ok").click( function() {var val = $("#popup_prompt").val();$.alerts._hide();if( callback ) callback( val );});$("#popup_cancel").click( function() {$.alerts._hide();if( callback ) callback( null );});$("#popup_prompt, #popup_ok, #popup_cancel").keypress( function(e) {if( e.keyCode == 13 ) $("#popup_ok").trigger('click');if( e.keyCode == 27 ) $("#popup_cancel").trigger('click');});if( value ) $("#popup_prompt").val(value);$("#popup_prompt").focus().select();break;case 'select':var result = '';for(var key in value){result+=('<option value="'+value[key].substr(0,value[key].lastIndexOf(','))+'">'+value[key].substr(value[key].lastIndexOf(',')+1,value[key].length)+'</option>');}$("#popup_message").append('<br /><select id="popup_select">'+result+'</select>').after('<div id="popup_panel"><input type="button" value="' + $.alerts.okButton + '" id="popup_ok" /> <input type="button" value="' + $.alerts.cancelButton + '" id="popup_cancel" /></div>');$("#popup_select").width( $("#popup_message").width() );$("#popup_ok").click( function() {var val = $("#popup_select").val();$.alerts._hide();if( callback ){callback( val );};});$("#popup_cancel").click( function() {$.alerts._hide();if( callback ) callback( null );});$("#popup_select, #popup_ok, #popup_cancel").keypress( function(e) {if( e.keyCode == 13 ) $("#popup_ok").trigger('click');if( e.keyCode == 27 ) $("#popup_cancel").trigger('click');});if( value ) $("#popup_select").val(value);$("#popup_select").focus().select();break;}// Make draggableif( $.alerts.draggable ) {try {$("#popup_container").draggable({ handle: $("#popup_title") });$("#popup_title").css({ cursor: 'move' });} catch(e) { /* requires jQuery UI draggables */ }}},_hide: function() {$("#popup_container").remove();$.alerts._overlay('hide');$.alerts._maintainPosition(false);},_overlay: function(status) {switch( status ) {case 'show':$.alerts._overlay('hide');$("BODY").append('<div id="popup_overlay"></div>');$("#popup_overlay").css({position: 'absolute',zIndex: 99998,top: '0px',left: '0px',width: '100%',height: $(document).height(),background: $.alerts.overlayColor,opacity: $.alerts.overlayOpacity});break;case 'hide':$("#popup_overlay").remove();break;}},_reposition: function() {var top = (($(window).height() / 2) - ($("#popup_container").outerHeight() / 2)) + $.alerts.verticalOffset;var left = (($(window).width() / 2) - ($("#popup_container").outerWidth() / 2)) + $.alerts.horizontalOffset;if( top < 0 ) top = 0;if( left < 0 ) left = 0;// IE6 fixif( $.browser.msie && parseInt($.browser.version) <= 6 ) top = top + $(window).scrollTop();$("#popup_container").css({top: top + 'px',left: left + 'px'});$("#popup_overlay").height( $(document).height() );},_maintainPosition: function(status) {if( $.alerts.repositionOnResize ) {switch(status) {case true:$(window).bind('resize', function() {$.alerts._reposition();});break;case false:$(window).unbind('resize');break;}}}}jAlert = function(message, title, callback) {$.alerts.alert(message, title, callback);}jConfirm = function(message, title, callback) {$.alerts.confirm(message, title, callback);};jPrompt = function(message, value, title, callback) {$.alerts.prompt(message, value, title, callback);};jSelect = function(message, value, title, callback) {$.alerts.select(message, value, title, callback);};})(jQuery);

jquery.alerts.css

#popup_container {BORDER-RIGHT: #999 5px solid;BORDER-TOP: #999 5px solid;FONT-SIZE: 12px;BACKGROUND: #fff;MIN-WIDTH: 300px; MAX-WIDTH: 600px;BORDER-LEFT: #999 5px solid;COLOR: #000;BORDER-BOTTOM: #999 5px solid;FONT-FAMILY: Arial, sans-serif;-moz-border-radius: 5px;-webkit-border-radius: 5px;border-radius: 5px;line-height:25px;}#popup_title {BORDER-RIGHT: #fff 1px solid;PADDING: 0;BORDER-TOP: #fff 1px solid;FONT-WEIGHT: bold;FONT-SIZE: 14px;BACKGROUND: url(images/title.gif) #ccc repeat-x 50% top;MARGIN: 0em;BORDER-LEFT: #fff 1px solid;CURSOR: default;COLOR: #666;BORDER-BOTTOM: #999 1px solid;TEXT-ALIGN: center}#popup_content {PADDING:13px 20px;BACKGROUND: url(images/info.gif) no-repeat 16px 16px;MARGIN: 0;}.alert#popup_content {BACKGROUND-IMAGE: url(images/info.gif);}.confirm#popup_content {BACKGROUND-IMAGE: url(images/important.gif)}.prompt#popup_content {BACKGROUND-IMAGE: url(images/help.gif)}#popup_panel {MARGIN: 1em 0em 0em 1em;TEXT-ALIGN: center}#popup_prompt {width:400px;height:50px;}


效果图


原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 ie浏览器页面显示网页错误怎么办 Ⅵvo手机声音小怎么办 小米手机预约错了怎么办 小米note二手没解锁怎么办 艾灸后脸色越黑怎么办 淘宝软件类目不能上架宝贝怎么办 ae中没有mpg格式怎么办 淘宝小二处理不公怎么办 遇到卖保险的人怎么办 租房合同没理家电清单怎么办 普雪油烟机坏了怎么办 我累了 真的累了怎么办 u盘15g变成4g了怎么办 属兔的买了东户怎么办 玩时时彩输了2万怎么办 胸变的又软又小怎么办 u盘16g变成4g了怎么办 1岁宝宝吃了就吐怎么办 脚崴了肿了很痛怎么办 九格拼图5在9那怎么办 4s锁屏密码忘了怎么办 6p触屏偶尔乱跳怎么办 新办劳务公司的劳务资质怎么办 汽车没电了打不着火怎么办 吃凉的甜的牙疼怎么办 学车对点对不上怎么办 发现老公有外遇最明智的怎么办 想开个童装店但是没经验怎么办 母乳不够吃宝宝又不喝奶粉怎么办 掉头发很厉害怎么办有什么偏方 红米2a刷死机了怎么办 公司退市我们买的股票怎么办 黑魂3把npc杀了怎么办 摔倒了膝盖摔肿了又痛怎么办 厕所堵了怎么办疏通马桶有妙招 月经不来怎么办如何让它快点来 苹果手机进水了开不了机怎么办 苹果5s进水了怎么办修要多少钱 吃了过期3年的药怎么办 离婚后孩子的抚养费不给怎么办 小车钥匙丢了怎么办配要多少钱