简体   繁体   English

如何根据与变量匹配的数据属性选择div?

[英]how to select a div based on the data attribute that matches a variable?

I am trying to use Jquery ui tabs with salesforce communities, if a user is being directed from a different page to the current page, based on the project id of the previous page, the current page needs to highlight the appropriate tab. 我正在尝试对Salesforce社区使用Jquery ui选项卡,如果将用户从其他页面引导到当前页面,则根据上一页的项目ID,当前页面需要突出显示适当的选项卡。

These tabs are generated based on how many project a user has which prevents me from giving them an ID inside the html 这些标签是根据用户拥有多少项目而生成的,这阻止了我在html内为他们提供ID

<script>
  $(document).ready(function(){
    var focusedProject = '{!focusedProjectId}';
    $('.projectTabs').each(function(){
       var id = $(this).data('salesforceprojectid');
       if(focusedProject === id){
         $('*[data-salesforceprojectid="HARD CODED ID"]').addClass('ui-state-active');
       }
    });
  });
</script>

Where you see the words hard coded Id i want to put the variable focusedProject - it doesnt seem this is possible, does anyone know an alternate solution for this? 在您看到硬编码Id的单词的地方,我想将变量focusedProject -看来这是不可能的,有人知道这个的替代解决方案吗?

<ul>
  <li class="projectTabs" data-salesforceprojectid="{!projectList.Id}"></li>
  <li class="projectTabs" data-salesforceprojectid="{!projectList.Id}"></li>
  <li class="projectTabs" data-salesforceprojectid="{!projectList.Id}"></li>
  <li class="projectTabs" data-salesforceprojectid="{!projectList.Id}"></li>
</ul>

you can't do 你做不到

$('*[data-salesforceprojectid="' + focusedProject  + '"]').addClass('ui-state-active');

to make the hard coded part into a variable? 使硬编码部分变成变量?

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

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