【问题标题】:Set by code data-theme in JQMobile通过 JQMobile 中的代码数据主题设置
【发布时间】:2014-08-05 16:38:56
【问题描述】:

我有一个使用 jquery mobile 和 javascript 创建的页面。我正在使用 ajax 从服务器检索一些数据以显示在页面上(描述、标题、...、数据主题)。

我已经在 html 和 javascript 中创建了我的页面代码,我有类似的东西:

$(document).on('pagebeforecreate', '#descripcion', function (event, ui) {
retrievePoiData();
function retrievePoiData(){
  var jsonFile = '{"poi":"' +  poiID + '"}';
  $.ajax({
          type: "POST",
          url: urlServer+"retrieveData.php",
          contentType: "application/json; charset=utf-8",
          dataType: "json",
          data: jsonFile,
          success: function(response) {
                  title = response['title'];
                  latitude = response['coordinates']['lat'];
                  ...

然后,在成功功能中,我设置了我网页的所有文本和图像:

          document.getElementById("title_poi").innerHTML = title;
          document.getElementById("image_poi").src = imageURL;
          document.getElementById("derecha_poi").innerHTML = description_short;
          document.getElementById("descr_larga_poi").innerHTML = description_long;

我可以在我的网页中看到它们。

但每次我尝试对数据主题做同样的事情时,我都做不到。主题始终是“a”。我有一个包含很多字符(a、b、c .....、v)的 css 文件。我没有在我的代码中找到任何对“a”的引用,所以我不知道为什么 jqm 会加载那个主题。

我只想在数据角色页眉和页脚中设置数据主题。不在更多的地方。正确的做法是什么?

如果您需要查看更多代码,请询问。

【问题讨论】:

  • 您使用的是哪个 jQM 版本?
  • jquery.mobile-1.4.0.min.js.
  • 您只想更改页眉/页脚吗?

标签: javascript jquery-mobile


【解决方案1】:

使用.toolbar() 方法更改页眉和/或页脚的主题。

$(".selector").toolbar({
    theme: "b" /* swatch */
});

.selector = [data-role=header][data-role=footer]#id.class

Demo

【讨论】:

  • 这行得通。谢啦。我已经失去了很多时间试图做到这一点。我还没有听说过工具栏。我现在就去读。
  • @Biribu 不客气。我添加了工具栏小部件 API 的链接。
猜你喜欢
  • 2012-09-16
  • 1970-01-01
  • 2020-03-28
  • 1970-01-01
  • 2010-10-27
  • 2013-04-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多