jQuery 每隔一个背景灰色

标签 jquery html css

好的,我有了这个 HTML,我正在尝试设置它的样式,以便购物车的每一行都从白色变为灰色。我知道使用 CSS3 可能更容易,但由于这需要 IE7 的支持,我认为 jQuery 可能是更好的途径。

        <div id="checkoutTable">
        <div id="checkoutRow" class="bold headline">
            <div id="checkoutCell" class="headline">Item <br>Number</div>
            <div id="checkoutCell" class="headline itemName">Item <br>Name</div>
            <div id="checkoutCell" class="headline">Quantity <br>Per Unit</div>
            <div id="checkoutCell" class="headline">Units Free <br>Remaining</div>
            <div id="checkoutCell" class="headline">Units <br>Ordered</div>
            <div id="checkoutCell" class="headline">Cost Per Unit <br>(USD)</div>
            <div id="checkoutCell" class="headline">Total Cost <br>(USD)</div>
        </div>
        <div id="checkoutRow" class="center cartCheckout">
            <div id="checkoutCell" class="first">FLT199</div>
            <div id="checkoutCell" class="first itemName">Vehicle Flyer</div>
            <div id="checkoutCell" class="first">1</div>
            <div id="checkoutCell" class="first">20</div>
            <div id="checkoutCell" class="first"><input name="unitsOrdered" id="" size="5"></div>
            <div id="checkoutCell" class="first">$10.00</div>
            <div id="checkoutCell" class="first">$0.00</div>
        </div>
        <div id="checkoutRow" class="center cartCheckout">
            <div id="checkoutCell" class="first">FLT199</div>
            <div id="checkoutCell" class="first itemName">Vehicle Flyer</div>
            <div id="checkoutCell" class="first">1</div>
            <div id="checkoutCell" class="first">20</div>
            <div id="checkoutCell" class="first"><input name="unitsOrdered" id="" size="5"></div>
            <div id="checkoutCell" class="first">$10.00</div>
            <div id="checkoutCell" class="first">$0.00</div>
        </div>
    </div>

然后我认为这个 jQuery 可以解决问题,但它不起作用。

  $(function() {
    $(".cartCheckout:even").css("background", "#ccc;");
  });

最佳答案

您有一个额外的;,颜色为#ccc;,这是无效的。如果将其更改为 #ccc,它将如演示中所示那样工作。

$(function() {
    $(".cartCheckout:even").css("background", "#ccc");
  });

参见 fiddle demo

关于jQuery 每隔一个背景灰色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18616205/

相关文章:

javascript - 在依赖于另一个字段选择的表单中隐藏表格的一部分

javascript - 如何仅在选择两个下拉菜单时触发事件?

html - Janrain Engage 社交登录在 Bootstrap 3 中看起来很困惑

javascript - 使用jQuery中的CSS函数设置多个div的 "left"边距

html - 向下滚动时,如何使其与我的视频重叠?

php - 如何处理Jquery.ajax触发的php脚本中的错误?

javascript - onclick 显示元素并隐藏其他元素

html - 不希望抓取包含的文件内容

jquery - 部分 View 更改之间未保留高度空间

javascript - 将元素的宽度设置为等于监视器大小而不改变缩放