简体   繁体   English

使用带参数的锚点 href

[英]Use anchor href with parameters

I'm combining all my html pages to one page by setting those pages into divs because I'm making mobile app by Jquery mobile There's one problem in converting process.我通过将这些页面设置为 div 将所有 html 页面合并到一个页面,因为我正在通过 Jquery mobile 制作移动应用程序在转换过程中存在一个问题。 By normal, by using multiple html pages, I can send parameter via URL to another page.通常,通过使用多个 html 页面,我可以通过 URL 将参数发送到另一个页面。 Like this像这样

$('#allList').append('<li><a href="deadlineDetail.html?id='+allDeadline.id+'" data-transition = "slide >'+ allDeadline.class +'<br>'+ allDeadline.duedate+'  '+ allDeadline.duetime+'<br>'+ allDeadline.description +'</a></li>');

However, now I'm moving the deadlineDetail.html page into a div with id = "deadlineDetail"但是,现在我将deadlineDetail.html 页面移动到id = "deadlineDetail" 的div

So I'm gonna use this code所以我要使用这个代码

 $('#allList').append('<li><a href="#deadlineDetail?id='+allDeadline.id+'" data-transition = "slide >'+ allDeadline.class +'<br>'+ allDeadline.duedate+'  '+ allDeadline.duetime+'<br>'+ allDeadline.description +'</a></li>');

But so terrible that it cannot transfer the parameter via URL.但是太糟糕了,它无法通过 URL 传输参数。 Is there anyway to make it work ?有没有办法让它工作?

使哈希成为您的 href 的最后一部分。

href="?id='+allDeadline.id+'#deadlineDetail"

You need to append that link just as link with no parameters, then you need to create a click function with the parameters like:您需要像不带参数的链接一样附加该链接,然后您需要使用如下参数创建一个click函数:

$('#allList').append('<li><a id="SOME_ID">'+ allDeadline.class +'<br>'+ allDeadline.duedate+'  '+ allDeadline.duetime+'<br>'+ allDeadline.description +'</a></li>');

$(document).on("click", "#SOME_ID", function(){
  // do your stuff with parameters
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM