设置按钮的尺寸

Setting of button's dimension

我正在尝试设置按钮尺寸,但该尺寸仅为活动区域设置,未反映在 ui。

添加

<input type="button" value="Input Button" id="b1" style="height:100px">

会产生

<div data-corners="true" data-shadow="true" data-iconshadow="true" data-wrapperels="span" data-theme="c" data-disabled="false" class="ui-btn ui-shadow ui-btn-corner-all ui-btn-up-c" aria-disabled="false">
  <span class="ui-btn-inner">
    <span class="ui-btn-text">Input Button</span>
  </span>
  <input type="button" value="Input Button" id="b1" style="height:100px" class="ui-btn-hidden" data-disabled="false">
</div>

以下代码将在 div 中进行任何点击后正确设置按钮的尺寸

$(document).ready(function()
{
  $("div").click(function(){
    $("#b1").parent().css('height',100);
  });
});

但是直接在ready函数中调用是不行的

$(document).ready(function()
{
  $("#b1").parent().css('height',100);
});

在我看来,在准备好的函数中设置高度时,按钮的父级 div 尚未创建。

编辑

确认
$(document).ready(function()
{

  $("#b1").click(function(){
    alert($("#b1").parent().prop('id'));
  });

  alert($("#b1").parent().prop('id'));
});

这将显示在执行文档就绪函数时,尚未创建按钮的父 div。

您的问题是您正在使用 jQuery 移动设备并将其视为普通的 jQuery 应用程序。

您不应在 jQuery Mobile 中使用文档就绪事件,因为 jQM 将在触发文档就绪后触发代码标记增强,从而使您的 CSS 更改无效。

您需要学习使用jQuery移动页面事件:https://api.jquerymobile.com/category/events/

您需要做的是将 document ready 替换为 pagecreate 事件:

$( document ).on( "pagecreate", "#yourPageID", function( event ) {
  alert( "This page was just enhanced by jQuery Mobile!" );
});

在此处阅读有关此问题的更多信息:jQuery Mobile: document ready vs. page events