使用功能更改文本并包含项目符号图像
Change text with function and include bullet images
我试图找出一些没有结果的东西。我有一个用作按钮的简单<img>
,如果我单击它,来自其他<h3>
元素的文本应该会更改。该部分正在工作,但我也试图在新文本中包含图像作为 Bullet 元素,但它不起作用,它也呈现为文本。这是我的实际代码:
.HTML:
<img id="button1" src="images/info.png"/>
<h3 class="text1"> Here's some temporal text </h3>
JAVASCRIPT:
$( "#button1").click(function() {
$(".text1").text('This will be the new text also including a bullet <img src="images/bullet.png" style="margin-right:10px;"/> And here continues the text, but seems to be that the bullet is not being rendered:( only as text');
});
你能帮我找到解决方案吗?
使用 .html()
而不是 .text()
,因为.text()
只会设置元素的textContent
,它不会插入提供的参数作为DOM Element
$("#button1").click(function() {
$(".text1").html('This will be the new text also including a bullet <img src="images/bullet.png" style="margin-right:10px;"/> And here continues the text, but seems to be that the bullet is not being rendered:( only as text');
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<img id="button1" src="images/info.png" />
<h3 class="text1"> Here's some temporal text </h3>
相关文章:
- 在Meteor项目中安装并包含npm模块后出错
- 为什么react/redux前端项目在package.json中包含生产依赖项
- 隐藏/显示包含单词的ul li项目.但只能入住李的子女
- 如何使用webpack将全局JS文件包含到我的React项目中
- 如何在从外部连接时将外部文件包含到node-js项目中
- 查找数组中项目包含子字符串的索引
- Javascript:从数组中删除包含带有侦听器的对象的项目的最佳方法
- 如何从包含1000个项目的数组中随机选择一个项目
- 如何将OpenCV包含在JavaScript项目中
- 使用功能更改文本并包含项目符号图像
- IE8 中的 element.attributes 包含太多项目
- 如何使用Jade正确地将Fusioncharts.js包含在Node Express项目中
- IE(仅)在幻灯片中悬停时获得最高边距?(CSS和链接到项目包含)
- 如何选择不包含类/id 的项目 - jquery.
- Javascript 库,一次包含两个项目
- 如何根据条件显示包含唯一项目符号的无序列表
- jQuery UI 可排序:检测表单元格中是否已包含项目
- 如何使用茉莉花检查对象是否包含项目
- 添加一个额外的
- ,其中包含项目值上每个现有的首字母
- 如何在html/javascript中包含项目文件夹外的文件