js程式碼修改頁面title:document.title=stuName+knlgName+"答題情況";

SieSteven發表於2017-03-08

大清早產品截了個圖,要把新開啟的頁面的title設定為:包含指定學生姓名、指定知識點名稱的標題。百度之,很簡單一句話:

document.title=stuName+knlgName+"答題情況";

由於頁面中有面包屑,且麵包屑的內容與上述要求比較類似。因此,直接獲取麵包屑的資料,展示出來即可。

		$.ajax({
				url : ajaxReqUrl,
				data : pageContent,
				success : function(resultData) {
					console.log(resultData);
					if (resultData == undefined || resultData == null) {
						return;
					}
					var breadcrumb = "";
					var knlgName = "";
					var className = "";
					var stuName = "";
					if (resultData.StudentClass == null
							|| resultData.StudentClass == undefined) {

					} else {
						if (resultData.StudentClass.className != undefined
								&& resultData.StudentClass.className != null) {
							className = resultData.StudentClass.className;
						}
						if (resultData.StudentClass.studentUserName != undefined
								&& resultData.StudentClass.studentUserName != null) {
							stuName = resultData.StudentClass.studentUserName;
						}
					}
					if (resultData.KnowledgePoints.knowledgePointName != null
							&& resultData.KnowledgePoints.knowledgePointName != undefined) {
						knlgName = resultData.KnowledgePoints.knowledgePointName;
					}
					breadcrumb = className + "<span>></span>" + stuName
							+ "<span>></span>" + knlgName;
					$(".studenttit").html(breadcrumb);
					document.title=stuName+knlgName+"答題情況";
				}
			});

最後一句是修改title的有效語句。

相關文章