我正在尝试查看这些 uls 中是否存在。我用 .length 对其进行了测试,但我不确定我是否做对了。即使 select-sub-domain 类中没有 li,它也会提示 yes。
if ($('ul.expul > li.select-sub-domain').length < 0) {
var sub_doma = "Not set";
alert("no");
} else {
alert("yes");
var sub_domain = $('li.select-sub-domain').attr('id');
var sub_domainSplit = sub_domain.split('-');
var sub_doma = sub_domainSplit[1];
}
<ul class="one expul">
<li class='select' id=eng-88>1</li>
<li class='select' id=eng-89>2</li>
<li class='select' id=eng-90>3</li>
<li class='select' id=eng-91>4</li>
<li class='select' id=eng-92>5</li>
<li class='select' id=eng-93>6</li>
<li class='select' id=eng-94>7</li>
<li class='select' id=eng-95>8</li>
<li class='select' id=eng-96>9</li>
<li class='select' id=eng-97>10</li>
<li class='select' id=eng-98>11</li>
<li class='select' id=eng-99>12</li>
</ul>
<ul class="two expul hide">
<li class='select' id=fin-100>1</li>
<li class='select' id=fin-101>2</li>
<li class='select' id=fin-102>3</li>
<li class='select' id=fin-103>4</li>
<li class='select' id=fin-104>5</li>
<li class='select' id=fin-105>6</li>
<li class='select' id=fin-106>7</li>
<li class='select' id=fin-107>8</li>
</ul>
<ul class="three expul hide">
<li class='select' id=three-108>1</li>
<li class='select' id=three-109>2</li>
<li class='select' id=three-110>3</li>
<li class='select' id=three-111>4</li>
<li class='select' id=three-112>5</li>
<li class='select' id=three-113>6</li>
</ul>