如何按钮文本传递到另一个页面? [英] How to pass button text to another page?

查看:156
本文介绍了如何按钮文本传递到另一个页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用jQuery移动的黑莓PlayBook应用程序,并在页面(实际上是一个 DIV 数据角色='页面),我已经得到了很多(比如125),每一个独特的文字按钮。我已经使用了 A 标记数据角色=页面这一点。

I'm making an app for the BlackBerry PlayBook using jQuery Mobile, and in a page (actually a div with data-role='page'), I've got a lot of (say, 125) buttons each with a unique text. I've used the a tag with data-role='page' for this.

有像上述单独的页面,但是在同一个HTML文件不同的内容。本页面的内容取决于在第1页点击的按钮。

There's a separate page like the above, but with different content in the same HTML file. The content in this page depends on the button clicked in the page 1.

所以我的问题是,我怎么能加载页面2,随着相关联的内容,按照第1页点击的按钮?我需要的文字传递的中间< A> < / A> 标签页2并相应地加载内容。

So my question is, how can I load the page 2, along with the associated content, according to the button clicked in page 1? I need to pass the text in the middle of <a> and </a> tags to the page 2 and load the content accordingly.

任何帮助非常AP preciated。

Any help greatly appreciated.

推荐答案

您可以使用URL本身来传递例如使用,然后在页面pageshow事件中的查询字符串中的数据被称为您检查并显示appropiate内容。

You can use the url itself to pass the data using the query string for example and then in the pageshow event of the page being called you check that and display the appropiate content.

按钮标记

<a href="#page2?btn=Hello">Button 1</a>

绑定到pageShow一段时间,它会被调用之前(它shouldnt't实际上需要在文档准备,因为它被授权,但假设这就是你开始你的应用程序,你可以在那里把它)。

Bind to pageShow some time before it will get called (it shouldnt't actually need to be in the document ready since it's being delegated, but assuming that's where you start your app you can place it there).

$(function() {
     $(document).delegate('#page2', 'pageshow', function (event, ui) {
                var qryStringResult = getParameterByName('btn'); //hello                     
        });  
});

从阿尔乔姆·巴格功能 - http://stackoverflow.com/a/901144/384985

 function getParameterByName(name) 
{
  name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
  var regexS = "[\\?&]" + name + "=([^&#]*)";
  var regex = new RegExp(regexS);
  var results = regex.exec(window.location.search);
  if(results == null)
    return "";
  else
    return decodeURIComponent(results[1].replace(/\+/g, " "));
}

这篇关于如何按钮文本传递到另一个页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆