让我们认为我们的URL看起来像
www.domain.com #CourseID#LessonID
我想做的是,当:
CourseDivButton单击了当前url $(this).data("id")添加为hashtag (www.domain.com #CourseID)CourseID (www.domain.com #CourseID),然后更改它(www.domain.com )CourseID和LessonID (www.domain.com,www.domain.com,然后删除秒,然后先更改(www.domain.com,#NEWCourseID) )
LessonDivButton单击了当前url CourseID (www.domain.com #CourseID),然后添加第二个(www.domain.com )CourseID和LessonID (www.domain.com,www.domain.com,然后更改秒,然后按原样离开) (www.domain.com,#CourseID#NEWLessonID) )
我的代码现在如下所示。我想不出怎么实现我想要的。
CourseDivButton.click(function(){
var id=$(this).data("id");
LoadLessons(id);
window.location.hash = id;
});
LessonDivButton.live("click", function(){
var id=$(this).data("id");
LoadQuestions(id);
window.location.hash = id;
});有什么建议吗?
发布于 2012-09-07 16:50:32
您不能使用查询字符串而不是使用hashtag吗?我建议你这样加起来:
www.domain.com?course=CourseID&lesson=LessonID
使用下面的javascript函数,您可以从URL中获取以下变量:
var courseID = urlParam('course');
var lessonID = urlParam('lesson');
function urlParam(name) {
/// <summary>
/// Gets the value of a parameter located within the url.
/// </summary>
/// <param name="name">The paramter to lookup.</param>
/// <returns type="string">The value of the requested parameter, or undefined if the parameter is not present.</returns>
name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
var regexS = "[\\?&]" + name + "=([^&#]*)";
var regex = new RegExp(regexS);
var results = regex.exec(window.location.href);
if (results == null)
return undefined;
else
return decodeURIComponent(results[1].replace(/\+/g, " "));
}如果需要在添加查询字符串的情况下构建新的URL,请使用check this out。
https://stackoverflow.com/questions/12321487
复制相似问题