简体   繁体   English

在引导弹出窗口中更改数据内容

[英]Change data-content in a bootstrap popover

I'm really new to coding, I've searched a bit to try to find an answer and I feel like there's a very simple way to do this, but the answers I find I can't understand. 我对编码真的很陌生,我经过了一些搜索来尝试找到答案,我觉得有一个非常简单的方法可以做到这一点,但是我无法理解答案。

I have this example which shows the popover. 我有一个显示弹出窗口的示例。

<span data-toggle="popover" title="Test" data-content="Test"
id="test">popover</span>

I want to change the content of data-content in my JavaScript file 我想在我的JavaScript文件中更改数据内容的内容

I tried this but it doesn't seem to work. 我试过了,但似乎没有用。

document.getElementById('test').setAtribute('data-content','hello');

As you are using jquery, try setting the value for content as shown below, 在使用jquery时,请尝试如下所示设置content的值,

 $('#test').data('content', 'hello'); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <span data-toggle="popover" title="Test" data-content="Test" id="test">popover</span> 

Javascript can be a dangerous tool... it can and will silently do nothing if what you write is not valid Javascript. Javascript可能是一种危险的工具...如果您编写的代码无效,它可以并且不会做任何事情。

So this line: document.getElementById('test').setAtribute('data-content','hello'); 所以这一行: document.getElementById('test').setAtribute('data-content','hello');

has a misspelling in 'SetAt t ribute', which tries to call a function that doesn't actually exist (since it's misspelled), and so it does nothing at all. 在“ SetAt t ribute”中有一个拼写错误,它试图调用一个实际上不存在的函数(因为它被拼写错误了),因此它什么也不做。

First step when debugging: re-read your code carefully! 调试时的第一步:仔细阅读代码!

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

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