【发布时间】:2015-03-03 20:02:13
【问题描述】:
当 UL 内的项目少于 3 li 时,我需要更改 ul li 项目的宽度。这是我创建的,但它不能正常工作,你能帮我解决它吗?
jQuery(document).ready(function($) {
if ($('ul.products li').length <= 3) {
$($this).css('width', '29%');
}})
该网站是http://www.demo.simplexweb.dk/shopdemo1/。它与 3 个产品的部分相关。如果有人添加新产品,css 应该不同。
谢谢, 汤姆
【问题讨论】:
-
您可能还需要发布您的 html,以便我们查看您的 html 的结构,并知道
.products是什么。 -
这听起来像是 XY 问题。 meta.stackexchange.com/questions/66377/what-is-the-xy-problem 请发布您的 HTML 和 CSS。您可能不需要 JavaScript。
-
$($this).css('width', '29%');应该是$('ul.products').css('width', '29%'); -
你应该得到一个错误说
Error: '$this' is undefined
标签: jquery css wordpress woocommerce