我有一個數組classNameList 我的HTML:獲得價值
<ul id="servicepricing">
<li>
<a href="/service/page/servicepricing?dpt=4&ServiceModelListId27071" class="ServiceModelListId27071 servicepricingicon">FR-S Automatic</a>
<span style="display: none;">Scion FR-S Automatic Service Pricing</span>
</li>
<li>
<a href="/service/page/servicepricing?dpt=4&ServiceModelListId27072" class="ServiceModelListId27072 servicepricingicon">FR-S Manual</a>
<span style="display: none;">Scion FR-S Manual Service Pricing</span>
</li>
<li>
<a href="/service/page/servicepricing?dpt=4&ServiceModelListId27061" class="ServiceModelListId27061 servicepricingicon">iQ Automatic</a>
<span style="display: none;">Scion iQ Automatic Service Pricing</span>
</li>
<li>
<a href="/service/page/servicepricing?dpt=4&ServiceModelListId124" class="ServiceModelListId124 servicepricingicon">tC Automatic</a>
<span style="display: none;">Scion tC Automatic Service Pricing</span>
</li>
<li>
<a href="/service/page/servicepricing?dpt=4&ServiceModelListId125" class="ServiceModelListId125 servicepricingicon">tC Manual</a>
<span style="display: none;">Scion tC Manual Service Pricing</span>
</li>
</ul>
最初我正在隱藏所有的表,當有人點擊上面的錨鏈接我要展示表具有相同的類名稱
<table id="FR-SManual" class="content sortable pureprice-data servicepricing-view ServiceModelListId27071" style="display: none;">
</table>
<table id="FR-SManual" class="content sortable pureprice-data servicepricing-view ServiceModelListId27072" style="display: none;">
</table>
<table id="FR-SManual" class="content sortable pureprice-data servicepricing-view ServiceModelListId27061" style="display: none;">
</table>
<table id="FR-SManual" class="content sortable pureprice-data servicepricing-view ServiceModelListId2124" style="display: none;">
</table>
<table id="FR-SManual" class="content sortable pureprice-data servicepricing-view ServiceModelListId125" style="display: none;">
</table>
var className,
classNameList = ["servicepricingicon", "main","ServiceModelListId27071"];
如何獲取以「ServiceModelListId」開頭的數組的值/ s。我試着用這個:
function fxnShowHide() {
var aElem = this,
classNameList = $(aElem).attr("class").split(' '),
tblwdhClassName;
if ($(aElem).hasClass('main')) {
$("#hero").show();
$("table.servicepricing-view").hide();
}
$.each(classNameList, function (key, value) {
if (value.indexOf("ServiceModelListId") === 0) {
tblwdhClassName = "table.servicepricing-view." + value;
}
});
$(tblwdhClassName).show();
}
$(".servicepricingicon").click(fxnShowHide);
是否有任何其他進程out.each或for?
如果要檢查它是否以該值開始,請將'> -1'更改爲== 0' – 2015-03-19 10:12:50