DOM 中新元素的 jQuery Mobile 格式化

标签 jquery css jquery-mobile knockout.js

我这里有一个 fiddle :http://jsfiddle.net/marktait/YETGp/

它是为使用 jQueryMobile 而设计的——这在它首次显示时很好。但是当我点击“添加房间”按钮时,它添加了一个新行,但 jQuery Mobile CSS 并未应用于新行。

是否可以为 DOM 中的新元素添加格式?

HTML 是:

<div class='liveExample'> 

    <table width='100%' border="1">
        <thead>
            <tr>
                <th width='25%'>Room Type</th>
                    <th width='25%'>Occs</th>
                <th class='price' width='15%'>Price</th>
                <th class='quantity' width='10%'>Quantity</th>
                <th class='price' width='15%'>Subtotal</th>
                <th width='10%'> </th>
            </tr>
        </thead>
        <tbody data-bind='foreach: lines'>
            <tr>
                <td>
                    <select data-bind='options: $root.RoomCategories, optionsText: "TypeName", optionsCaption: "Select...", value: category'> </select>
                </td>
                <td data-bind="with: category">
                    <select data-bind='options: Occs, optionsText: "occ", optionsCaption: "Select...", value: $parent.product'> </select>
                </td>
                <td class='price' data-bind='with: product'>

<span data-bind='text: formatCurrency(ratetocharge)'> </span>
                </td>
                <td class='quantity' data-bind="with: category">
                    <select data-bind="visible: $parent.product, options: ko.utils.range(0, TypeCount), value: $parent.quantity"></select>
                </td>
                <td class='price'>
                    <span data-bind='visible: product, text: formatCurrency(subtotal())' > </span>
                </td>
                <td>
                    <a href='#' data-bind='click: $parent.removeLine'>Remove</a>
                </td>
            </tr>
        </tbody>
    </table>
    <p class='grandTotal'>
        Total value: <span data-bind='text: formatCurrency(grandTotal())'> </span>
    </p>
    <button data-bind='click: addLine'>Add room</button>
    <button data-bind='click: save'>Submit booking</button>

</div>

添加新行的 KnockOut 是:

// Operations
self.addLine = function() {
self.lines.push(new CartLine())
};

感谢您的帮助,

标记

最佳答案

你应该看看documentation here .

当您向页面添加内容时,您需要通知框架。在表格行的情况下,(根据您的内容猜测),您需要在其上触发创建事件。

$('.line_selector').trigger('create');

不幸的是,我没有 knockout 的经验,所以我无法指导您应该在哪里进行调用。

关于DOM 中新元素的 jQuery Mobile 格式化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14256674/

相关文章:

javascript - 滚动太远

javascript - 使用 PHP 和 Jquery 进行实时电子邮件通知

jquery - javascript - 想要使用 ajax 访问另一个域的内容吗?

java - ajax 发布后需要在下一个选项卡上显示数据库中的数据

html - 简单的 CSS 给 IE 9 带来麻烦

javascript - Heroku "We' 抱歉,出了点问题。”由于 javascript_include_tag

button - jQuery Mobile 按钮启用/禁用和 TextArea 更改后自动调整大小

html - Bootstrap 选项卡内容下降

jquery - 带有 Bootstrap 的窗口右下角的 Bootstrap 固定按钮

jquery - 如何使用 HTML5、JQuery 移动设备中的链接在同一页面内进行内部导航?