简体   繁体   English

如何使多个 ul 的每个 li 具有相同的 class

[英]how to each li of multiple ul with same class

I have multiple ul with different data attr(data-status) if data-status is equal to data-step then it will add class name "half" -1.我有多个具有不同数据 attr(data-status) 的 ul,如果 data-status 等于 data-step,那么它将添加 class 名称“half”-1。 li will have the class name "active" and the rest will have the class name 'complete' but if data-step equals data-status, it will add the class name "finish" and the rest of the li will have the class name "complete". li 将具有 class 名称“active”,rest 将具有 class 名称“complete”,但如果 data-step 等于 data-status,它将添加 class 名称“finish”,li 的 rest 将具有 8219511 8219511 “完全的”。

 <ul class="progressbar" data-status="3">
      <li data-step="1" /*need to add class "complete"*/>aa</li>
      <li data-step="2" /*need to add class "active"*/>bb</li>
      <li data-step="3" /*need to add class "half"*/>cc</li>
      <li data-step="4" /*there will be no class"*/>dd</li>
      <li data-step="5" /*there will be no class"*/>ee</li>
 </ul>

 <ul class="progressbar" data-status="4">
      <li data-step="1" /*need to add class "complete"*/>aa</li>
      <li data-step="2" /*need to add class "complete"*/>bb</li>
      <li data-step="3" /*need to add class "active"*/>cc</li>
      <li data-step="4" /*need to add class "half"*/>dd</li>
      <li data-step="5" /*there will be no class"*/>ee</li>
 </ul>

<ul class="progressbar" data-status="5">
      <li data-step="1" /*need to add class "complete"*/>aa</li>
      <li data-step="2" /*need to add class "complete"*/>bb</li>
      <li data-step="3" /*need to add class "complete"*/>cc</li>
      <li data-step="4" /*need to add class "complete"*/>dd</li>
      <li data-step="5" /*need to add class "finish"*/>ee</li>
 </ul>

I am not entirely sure I understand what you are trying to ask.我不完全确定我明白你想问什么。

I assume you are looking for a function that will return a string (for a class name) that is one of( '', 'complete', 'half', 'finish') based on the value of a variable dataStatus.我假设您正在寻找一个 function,它将根据变量 dataStatus 的值返回一个字符串(对于 class 名称),它是(''、'complete'、'half'、'finish')之一。

If that is the case then your ul could look something like this:如果是这种情况,那么您的 ul 可能看起来像这样:

            <ul className="progressbar" data-status={dataStatus}>
                <li data-step="1" class={getClassName(1, dataStatus)} >aa</li>
                <li data-step="2" class={getClassName(2, dataStatus)} >bb</li>
                <li data-step="3" class={getClassName(3, dataStatus)} >cc</li>
                <li data-step="4" class={getClassName(4, dataStatus)} >dd</li>
                <li data-step="5" class={getClassName(5, dataStatus)} >ee</li>
            </ul>

and the getClassName function could be something like this:而 getClassName function 可能是这样的:

    const getClassName = (dataStep, dataStatus) => dataStatus > dataStep ? '' : dataStatus === dataStep ? dataStatus === '5' ? 'finish' : 'half' : 'complete'

But I don't really know what you are asking.但我真的不知道你在问什么。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM