如何使用jQuery更改警报消息的按钮文本 [英] How to change button text of Alert message using jQuery

查看:101
本文介绍了如何使用jQuery更改警报消息的按钮文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我在om internet上找到了一个js文件来修改警报消息,但是我不想使用文本"OK",我想将其更改为文本"Back".但它没有运行,我不明白这是什么问题.

希望能得到您的帮助.
文件代码:

Hi All,

I find out om internet a js file to modify alert message, But I don''t want to use text "OK" , i want to change it to text "Back". but it don''t run, I don''t understand what is issue.

I hope that will be received help from you.
code of file:

(function($) {
	
	$.alerts = {
		
		// These properties can be read/written by accessing $.alerts.propertyName from your scripts at any time
		
		verticalOffset: -75,                // vertical offset of the dialog from center screen, in pixels
		horizontalOffset: 0,                // horizontal offset of the dialog from center screen, in pixels/
		repositionOnResize: true,           // re-centers the dialog on window resize
		overlayOpacity: .01,                // transparency level of overlay
		overlayColor: '#FFF',               // base color of overlay
		draggable: true,                    // make the dialogs draggable (requires UI Draggables plugin)
		okButton: ' 戻る ',         // text for the OK button
		cancelButton: ' Cancel ', // text for the Cancel button
		okButton1: ' Back ',       // text for the OK button of modified message dialog
		dialogClass: null,                  // if specified, this class will be applied to all dialogs
		
		// Public methods
		
		alert: function(message, title, modified, callback) {
			if( title == null ) title = 'Alert';			
			$.alerts._show(title, message, null, 'alert', modified, function(result) {
				if( callback ) callback(result);
			});
			
		},
				
		confirm: function(message, title, callback) {
			if( title == null ) title = 'Confirm';
			$.alerts._show(title, message, null, 'confirm', modified, function(result) {
				if( callback ) callback(result);
			});
		},					
		
		// Private methods
		
		_show: function(title, msg, value, type, modified, 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 Fix
			var pos = ($.browser.msie && parseInt($.browser.version) <= 6 ) ? 'absolute' : 'fixed'; 
			
						
			$("#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':
					if(modified == null || modified== 'false'){
						$("#popup_message").after('<div id="popup_panel"><input type="button" value="' + $.alerts.okButton + '" id="popup_ok" /></div>');
					} else {
						$("#popup_message").after('<div id="popup_panel"><input type="button" value="' + $.alerts.okButton1 + '" 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;		
								
			}
			
			// Make draggable
			if( $.alerts.draggable ) {
				try {
					$("#popup_container").draggable({ handle: $("#popup_title") });
					$("#popup_title").css({ cursor: 'move' });
				} catch(e) { /* requires jQuery UI draggables */ }
			}
		},
				
	}
	
	// Shortuct functions
	jAlert = function(message, title, modified, callback) {
		$.alerts.alert(message, title, modified, callback);
	}
		
	jConfirm = function(message, title, callback) {
		$.alerts.confirm(message, title, callback);
	};
	
})(jQuery);



htlm中的呼叫代码:



call code in htlm:

function changeNext()
        {

            jAlert('Serial number is not submitted', 'Error Message', 'true');
        }



预先感谢.



Thank in advance.

推荐答案

){


.alerts = { // 通过访问
.alerts = { // These properties can be read/written by accessing


.alerts.propertyName可以读取/写入这些属性.随时从您的脚本中删除 verticalOffset:-75,// 对话框与中心屏幕的垂直偏移,以像素为单位 horizo​​ntalOffset: 0 // 对话框相对于对话框的水平偏移中心屏幕,以像素/为单位 repositionOnResize: true // 将对话框重新居中调整窗口大小 overlayOpacity:. 01 // 覆盖层的透明度 overlayColor:' #FFF'// 叠加层的基本颜色 可拖动的: true // 使对话框可拖动(要求UI Draggables插件) okButton:' 戻る'// 确定"按钮的文本 cancelButton:' 取消'// 取消按钮的文本 okButton1:' 返回'// 修改后的消息对话框的确定"按钮的文本 dialogClass:// (如果指定),则此类应用于所有对话框 // 公共方法 警报:功能(消息,标题,已修改,回调){ 如果(title == )title = ' 警告';
.alerts.propertyName from your scripts at any time verticalOffset: -75, // vertical offset of the dialog from center screen, in pixels horizontalOffset: 0, // horizontal offset of the dialog from center screen, in pixels/ repositionOnResize: true, // re-centers the dialog on window resize overlayOpacity: .01, // transparency level of overlay overlayColor: '#FFF', // base color of overlay draggable: true, // make the dialogs draggable (requires UI Draggables plugin) okButton: ' 戻る ', // text for the OK button cancelButton: ' Cancel ', // text for the Cancel button okButton1: ' Back ', // text for the OK button of modified message dialog dialogClass: null, // if specified, this class will be applied to all dialogs // Public methods alert: function(message, title, modified, callback) { if( title == null ) title = 'Alert';


这篇关于如何使用jQuery更改警报消息的按钮文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆