使用javascript设置HTML img标题属性
Set an HTML img title attribute using javascript
更新:标题拉正确,但在Internet Explorer中图像的标题不显示。适用于Firefox和Chrome。我无法理解它,我在说这个:
<script type="text/javascript" src="//www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<html>
<i><strong><a href="__URL__" target="_blank">PDW Status: </a></strong></i>
<a href="__URL__" target="_blank"></a>
<a href="__URL__" target="_blank"><br/></a>
<a href="__URL__" target="_blank">Green</a> -
<img id="Green" class="ms-rtePosition-4 ms-rteImage-2 ms-rteStyle-Emphasis" alt="lightgreen1.jpg"
src="__URL__" style="margin: 5px;"/></em>     
<a href="__URL__" target="_blank">Red</a> -
<img id="Red" class="ms-rtePosition-4 ms-rteImage-2 ms-rteStyle-Emphasis" alt="red1.jpg"
src="__URL__" style="margin: 5px;"/></em>     
<a href="__URL__" target="_blank">Yellow</a> -
<img id="Yellow" class="ms-rtePosition-4 ms-rteImage-2 ms-rteStyle-Emphasis" alt="yellow1.jpg"
src="__URL__" style="margin: 5px;"/>     
<a href="__URL__" target="_blank">White</a>  -
<img id="White" class="ms-rteImage-2 ms-rtePosition-4" alt="white.jpg"
src="__URL__" style="margin: 5px;"/> 
</html>
<style>
a:link { text-decoration: none;
color: #0072c6 } a:visited { text-decoration: none; color: #0072c6 } a:hover { text-decoration: underline; } a:active { text-decoration: underline; }
</style>
<script type="text/javascript">
//Grab data from list and post into HTML Fields
$(function() {
green = "";
yellow = "";
red = "";
white = "";
$.ajax({
url: "__URL__",
headers: {"Accept": "application/json;odata=verbose"},
type: "GET",
cache: false,
async: false,
}).success(function (data) {
$.each(data.d.results, function(key, value) {
console.log(value.Title);
switch (value.Title) {
case "GREEN":
green += value.Description;
console.log("GREEN TEST" + green);
var gDescription = document.querySelector('#Green');
gDescription.title = "" + green;
break;
case "YELLOW":
yellow += value.Description;
console.log("YELLOW TEST" + yellow);
var yDescription = document.querySelector('#Yellow');
yDescription.title = "" + yellow;
break;
case "RED":
red += value.Description;
console.log("RED TEST" + red);
var rDescription = document.querySelector('#Red');
rDescription.title = "" + red;
break;
default:
white += value.Description;
console.log("WHITE TEST" + white);
var wDescription = document.querySelector('#White');
wDescription.title = "" + white;
}
});
});
});
</script>
这是一个相关的问题,但似乎没有解决它:为什么我可以't设置一个ascii引用在一个img标题属性使用js?
你试过了吗:
var image = document.querySelector('img');
image.title = 'Your title'; // Assigning directly to attribute.
image.setAttribute('title', 'Your other title'); // Assigning by method.
这是如何使用javascript设置HTML图像标题属性
相关文章:
- 根据值向表的每个 td 添加标题属性
- 正在为禁用的输入设置标题属性
- 为HTML文本区域设置标题属性的样式
- HTML “标题”属性显示单词“未定义” - 例如.“主页未定义”
- 火狐中的标题属性
- 使剑道 UI 下拉列表将“选择控件”的“标题”属性显示为剑道工具提示
- 更改动态表中标题属性的格式
- 如何使用javascript从类中的链接获取标题属性
- “a”标记中标题属性末尾的空格
- 如何添加范围的标题属性值
- jQuery从标题属性获取动态生成的内容
- 将标题属性添加到现有 HTML 的某个位置
- 尝试在火狐扩展中获取标题属性时出错
- 在 asp.net 中使用 javascript 显示标题属性消息
- 引导灯箱:显示标题属性中的图像说明
- 标题属性中的 img 标记
- 在点击函数中将 HTML 标题属性的值作为变量进行访问
- 如何将标题属性添加到d3生成的力定向图的节点中
- 如何将“标题”属性发送到FancyBox库图像
- Kendo UI网格-单元格上的标题属性