【问题标题】:jQuery Mobile forms combining input elements结合输入元素的 jQuery Mobile 表单
【发布时间】:2014-02-21 12:19:03
【问题描述】:

使用 jQuery mobile 时,是否可以将复选框或按钮与文本输入结合使用?如下图所示。

我想用它作为字段验证,这样当用户更新字段时它会变成红色或绿色。

【问题讨论】:

    标签: jquery-mobile jquery-mobile-fieldset


    【解决方案1】:

    jQuery Mobile 不包含此功能,但您可以通过 CSS 实现。

    这是一个 DEMO 有几个选项

    第一个使用表格,所以左键总是相同的大小,并且输入在窗口调整大小时增长/缩小。而第二个选项使用 div 并且按钮和标签都变小了。

    为表格,css 删除表格上的边框和间距,并将第一个 td 宽度设置为恒定值。其余的 css 使按钮和输入看起来正确:

    <table id="specialContTbl">
      <tr>
        <td class="btntd">
          <button data-role="none" id="btn">B</button>
        </td>
        <td class="inptd">
          <input data-role="none" type="text" id="inp1" name="inp1" value="" placeholder="enter some text" />
        </td>
      </tr>
    </table>
    
    #specialContTbl {
        border-spacing: 0;
        border-collapse: collapsed;
    }
    #specialContTbl td {
        padding:0;
        margin: 0;
        border: 0;
        vertical-align: top;
    }
    #specialContTbl td:first-child{
        width: 60px;
    }
    #specialContTbl{
        width: 100%;
    }
    #specialContTbl button, #specialContTbl input {
        -webkit-box-sizing: border-box;
        -moz-box-sizing: border-box;
        box-sizing: border-box;
    }
    #specialContTbl button {
        font-weight: normal;
        background: #00f050;
        padding: 5px;
        color: #333;
        border: 1px solid #d4d4d4;
        border-right: 0;
        border-bottom-left-radius:1em;
        border-top-left-radius: 1em;    
        line-height: 28px;
        height: 38px;
        width: 100%;
        float: left;
        text-align: center;
        cursor: pointer;
        white-space:nowrap;
    }
    #specialContTbl input {
        width: 100%;
        height: 38px;
        padding: 8px;
        border: 1px solid #d4d4d4;
        border-bottom-right-radius: 1em;
        border-top-right-radius: 1em;
        line-height: 18px;
        float: right;
        box-shadow: inset 0px 2px 2px #ececec;
    }
    #specialContTbl input:focus {
        outline: 0;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-20
      • 2013-05-28
      • 1970-01-01
      相关资源
      最近更新 更多