ITeye博客

javascript的作用范围实例

夜鸣猪 · 2010-07-15 07:52 · javascript Jquery ext prototype · Web前端 · Markdown

局部变量key点击的时候得到不能在dialog open的时候掉用到,所以用了下面的解决办法:


$(".help").click(function() {
	//Create the help dialog if needed.
	var key = $(this).attr("data-help-key");
        alert(key);
	if ($.find("#help-dialog").length == 0){
		$(document.body).append('<div id="help-dialog"><div class="dialog_content"><div class="dialog_title"><span>Yottaa Help Documentation</span>'+
						'Loading Help Content...</div><div class="help_content"></div></div></div>');
						
		$("#help-dialog").dialog({
			autoOpen: false,
			dialogClass: 'help_dialog',
			draggable: true,
			resizable: false,
			height: 340,
			width: 450,
   			open: function(event, ui) {
				// Need to add the loading screen and fetch the help content async style from the server.
				//Show the loading screen.						
				$(".help_content").html('<div style="margin:50px 185px"><img src="/images/animated/widget-loader-gray.gif" alt="Loading..."/></div>');
				
				$.get("/helps?id="+$(this).dialog('option', 'url_key')+"&type=help", function(data) {
					$(".dialog_content").html(data);
				});			
							
				//TODO - Improvements cache the contents.
			}
		});
	}
	
	$("#help-dialog").dialog("option", 'url_key', key );
	$("#help-dialog").dialog("open");
	return false;
});


后来发现也可以不用option传


		/*** Create and attach the help dialog.
		 */
		$(".help").click(function() {
			if ($.find("#help-dialog").length == 0){
				$(document.body).append('<div id="help-dialog"><div class="dialog_content"><div class="dialog_title"><span>Yottaa Help Documentation</span>'+
								'Loading Help Content...</div><div class="help_content"></div></div></div>');
								
				$("#help-dialog").dialog({
					autoOpen: false,
					dialogClass: 'help_dialog',
					draggable: true,
					resizable: false,
					height: 340,
					width: 450
				});				
			}
			
			//Create the help dialog if needed.
			var key = $(this).attr("data-help-key");
			
			//Add the open handler
			$("#help-dialog").dialog("option", {
	   			open: function(event, ui) {
					//Need to add the loading screen and fetch the help content async style from the server.					
					//Show the loading screen.						
					$(".help_content").html('<div style="margin:50px 185px"><img src="/images/animated/widget-loader-gray.gif" alt="Loading..."/></div>');
					
					$.get("/helps?id=" + key + "&type=help", function(data) {
						$(".dialog_content").html(data);
					});			
								
					//TODO - Improvements cache the contents.
				}
			});				
			$("#help-dialog").dialog("open");
			return false;
		});


评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。