jquerymobile attibute数据角色=";按钮“;无效

jquerymobile attibute数据角色=";按钮“;无效,jquery,jquery-mobile,Jquery,Jquery Mobile,我想在调整窗口大小时从锚定标记中添加或删除jquerymobile属性data role=“button”,其含义如下: <a href=".." class="mobilebutton">Hello</a> if(windowsize < 700) $(".mobilebutton").attr("data-role", "button"); else $(".mobilebutton").removeAttr("data-role

我想在调整窗口大小时从锚定标记中添加或删除jquerymobile属性
data role=“button”
,其含义如下:

  <a href=".." class="mobilebutton">Hello</a>

  if(windowsize < 700)
    $(".mobilebutton").attr("data-role", "button");
  else 
    $(".mobilebutton").removeAttr("data-role");

如果(窗口大小<700)
$(“.mobilebutton”).attr(“数据角色”、“按钮”);
其他的
$(“.mobilebutton”).removeAttr(“数据角色”);
但它不起作用可能是因为页面已经创建,所以添加
数据角色
属性没有效果,因为
jquerymobile.js
不知道我们添加的这个属性。
有人能告诉我这方面的解决方法吗?

在jQueryMobile增强标记之前触发的事件中,您可以调用您的逻辑。

当页面已创建(因此标记已增强)时,您不能通过删除属性来恢复增强

按钮标记:

<a id="myButton" href="index.html" data-role="button">Link button</a>

增强后的外观如下所示:

<a id="myButton" href="index.html" data-role="button" data-corners="true" data-shadow="true" data-iconshadow="true" data-wrapperels="span" data-theme="c" class="ui-btn ui-shadow ui-btn-corner-all ui-btn-up-c">
    <span class="ui-btn-inner ui-btn-corner-all">
        <span class="ui-btn-text">Link button</span>
    </span>
</a>

因此,消除增强标记的一种方法是手动将其替换为预增强标记:

$("#myButton").replaceWith('<a id="myButton" href="index.html">Link button</a>'); 
$(“#我的按钮”)。替换为(“”);

这是一个类似的问题。我举了一个应该对你有帮助的例子。谢谢你的回答,但我已经在问题中提到“页面已经创建了”,我们只是调整窗口的大小