1. 程式人生 > >jquery ui tab ajax 切換,預設選中第一個(序號為0)

jquery ui tab ajax 切換,預設選中第一個(序號為0)

   <script>
	$(function() {
		var tabss = $('#tabs').tabs();//[object,object]
		var selectedTab = tabss.tabs('option', 'selected');
		if(0==selectedTab){
			 $.ajax({
	    	        url: "<%=basePath %>TopicSectionServlet.serv",
	    	        type: "post",
	    	        data: "key=" + name + "&doaction=check",
	    	        dataType: "json",
	    	        error:function(){
	    	        	//dealFail();
	    	        	alert('fail');
	    	        },
	    	        success: function (data) {
	    	        	$("#atab2").html("成功-按部門1111");
	    	        }
	    	    });
		}
		$("#tabs").tabs({
			  select: function(event, ui) {
				  var name='5b92ed07-ba11-4d3d-bb6b-f642be25d46a';
				  var htmlStr = "";
				  if (ui.index == 0) {
					  $.ajax({
			    	        url: "<%=basePath %>TopicSectionServlet.serv",
			    	        type: "post",
			    	        data: "key=" + name + "&doaction=check",
			    	        dataType: "json",
			    	        error:function(){
			    	        	//dealFail();
			    	        	alert('fail');
			    	        },
			    	        success: function (data) {
			    	        	$("#atab2").html("成功-按部門1111");
			    	        }
			    	    });
			  }
				  //
				  if (ui.index == 1) {
					  $.ajax({
			    	        url: "<%=basePath %>TopicSectionServlet.serv",
			    	        type: "post",
			    	        data: "key=" + name + "&doaction=check",
			    	        dataType: "json",
			    	        error:function(){
			    	        	//dealFail();
			    	        	alert('fail');
			    	        },
			    	        success: function (data) {
			    	        	$("#btab2").html("成功-按部門2222");
			    	        }
			    	    });
				  }
				  //
				   if (ui.index == 2) {
					   $.ajax({
			    	        url: "<%=basePath %>TopicSectionServlet.serv",
			    	        type: "post",
			    	        data: "key=" + name + "&doaction=check",
			    	        dataType: "json",
			    	        error:function(){
			    	        	//dealFail();
			    	        	alert('fail');
			    	        },
			    	        success: function (data) {
			    	        	$("#ctab2").html("成功-按部門3333");
			    	        }
			    	    });
				  }
				  //
				   if (ui.index == 3) {
					   $.ajax({
			    	        url: "<%=basePath %>TopicSectionServlet.serv",
			    	        type: "post",
			    	        data: "key=" + name + "&doaction=check",
			    	        dataType: "json",
			    	        error:function(){
			    	        	//dealFail();
			    	        	alert('fail');
			    	        },
			    	        success: function (data) {
			    	        	$("#dtab2").html("成功-按部門4444");
			    	        }
			    	    });
				  }
				  //
				   if (ui.index == 4) {
				    		$.ajax({
				    	        url: "<%=basePath %>TopicSectionServlet.serv",
				    	        type: "post",
				    	        data: "key=" + name + "&doaction=check",
				    	        dataType: "json",
				    	        error:function(){
				    	        	//dealFail();
				    	        	alert('fail');
				    	        },
				    	        success: function (data) {
				    	        	$("#etab2").html("成功-按部門5555");
				    	        }
				    	    });
				  }
				  //
				 }
			});
	});
	</script>


//
				  if (ui.index == 1) {
						//載入版塊資料
					  $.ajax({
			    	        url: "<%=basePath %>TopicServlet.serv",
			    	        type: "post",
			    	        data: "key=" + name + "&doaction=statisticsBySectionId",
			    	        dataType: "json",
			    	        error:function(){
			    	        	alert('資料載入失敗!');
			    	        },
			    	        success: function (data) {
			    	         var len=data.length; 
			    	         //所有版塊
					         $('#sectionName-s').contents().remove();  
					         $('<option >請選擇</option>').appendTo('#sectionName-s'); 
					         for(i=0;i<len;i++){ 
					        	 $("#sectionName-s").append($('<option value='+data[i].tsb.id+'>'+data[i].tsb.sectionName+'</option>'));
					         } 
					         //所有資料
			    	        	$("#btab2").html("成功-按部門2222");
			    	        }
			    	    });
				  }