【问题标题】:Add on-click event code to a LabelField将点击事件代码添加到 LabelField
【发布时间】:2016-06-27 20:59:02
【问题描述】:

在我的应用程序中有一个带有文本“www.google.com”的 LabelField 当用户点击时,默认浏览器应该打开到 www.google.com。

【问题讨论】:

    标签: blackberry java-me


    【解决方案1】:

    试试这个代码

    final LabelField label = new LabelField("http://www.google.com",LabelField.FOCUSABLE){
                public boolean navigationClick (int status , int time){
                     BrowserSession bSession = Browser.getDefaultSession();
                     bSession.displayPage(label.getText());
                     return true;
                }
            };
    

    【讨论】:

      【解决方案2】:

      你可以使用 Jquery。 试试这个代码:

      <html>
      <head>
      <title>Opens a link</title>
      <script type="text/javascript" src="http://code.jquery.com/jquery-1.5.js"></script>
      </head>
      <body>
      <label for="link" id="target">www.google.com</label>
      <script type="text/javascript">
          $('#target').click(function () {
              var url = $(this).text();
              window.location = "http\://"+url;
          });
      </script>
      </body>
      </html>
      

      【讨论】:

        猜你喜欢
        • 2013-05-08
        • 2013-02-11
        • 2013-04-10
        • 2014-04-22
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-09-26
        相关资源
        最近更新 更多