[英]Change href attribute by jQuery in jQuery Mobile
我正在通过jQuery Mobile创建一个应用程序。
我想要一个链接,该链接重定向到页面。 例如:
<a href="/Account/" data-transition="turn" class="useroptions">Account</a>
它在所有页面上都可用,我想将每个页面上的链接的href
更改为以下形式:
<a href="/Account/?returnUrl=http%3A%2F%2Fexample.com%2FAbout" data-transition="turn" class="useroptions">Account</a>
我已经编写了这段代码,但是当jQuery Mobile使用Ajax导航加载页面时 ,它不起作用:
$(function () {
$(".useroptions").attr("href", "/Account/?returnUrl=" + encodeURIComponent(document.URL));
});
显示每个页面时该怎么做? (我应该使用哪个事件?...)
我应该使用jQuery Mobile的pageshow
事件。 参见pageshow
此页面的一部分。
修改后的jQuery代码版本可以正常工作:
$("div[data-role='page']").live("pageshow",function() {
$(".useroptions").attr("href", "/Account/?returnUrl=" + encodeURIComponent(document.URL));
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.