简体   繁体   English

将弹出窗口的数据内容存储在变量中

[英]Store data-content of popover in variable

I am trying to build a search engine for my website and I need to store to data-content of the popovers in a variable so that I can search for them afterwards. 我正在尝试为我的网站构建搜索引擎,并且需要将弹出式窗口的数据内容存储在变量中,以便以后可以搜索它们。

I already tried this: 我已经试过了:

var popover = $('.companyRoster').data('bs.popover');
popover.getContent();

but it is not working, as expected.. 但它没有按预期工作。

An example of my html containing the popover will be: 我的包含弹出窗口的html示例为:

<div id="companyRoster" class="companyRoster container">
  <div class="row mb-2">
    <div class="col-lg-1 col-md-2 col-sm-3 col-6">
        <img src="images/john-doe.jpg" alt="..." class="img-fluid rounded-circle padding-0" data-toggle="popover" title="John Doe" data-placement="top" data-content='<b>Position:</b> Team Leader Integration Services <br> <b>Department:</b> IT <br> <b>Email:</b> <a href="mailto:some.email@aaa.aa">some.email@aaa.aa</a> <br> <b>Skype:</b> <a href="skype:johndoe?userinfo">johndoe</a>'>
    </div>
  </div>
</div>

Can you tell me how can I make console.log() to display the data-content of the popover? 您能告诉我如何使console.log()显示弹出窗口的数据内容吗?

You're looking in the '#companyRoster' element for the data, which that element doesn't have. 您正在查找“ #companyRoster”元素中的数据,而该元素没有该数据。 The data-content is in one of the child elements. 数据内容位于子元素之一中。

You should be able to get the data-content like so: 您应该能够像这样获取数据内容:

var dataContent = $(".img-fluid").data('content');
document.getElementById('other_div').innerHTML = dataContent;

I hope this helps! 我希望这有帮助!

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

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