要求读取Json对象,并将该值显示在鼠标上方的工具提示上。 请找到http://jsfiddle.net/8WKTj/49/读取json并显示onmouse的动态值
下面的代码是将JSON代码:
jsonDataFile.js
{
"Column1": "This represents transID",
"Column2": "This represents Spread percentage",
"Column3": :" Column3 title description";
}
的javascript:
$(function()
{
$(".question").each(function(index)
{
$.getJSON("js/jsonDataFile.js",function(result){
$.each(result, function(i, field){
alert(" i: " + i +" ,"+ field); //prints i: column1 ,This represents transID
//i: column2 , This represents Spread percentage
$(this).prop('title', result[index]);
});
});
});
});
当我鼠标悬停在列1,提示应显示消息“This represent transID”。同样,当鼠标悬停在第2栏上时,工具提示应该显示“这代表传播百分比”......我尝试阅读json文件并在工具提示上显示消息,但输出与预期不符。它没有展示任何东西。请建议。
你可以将json数据文件的完整路径添加到jsfiddle吗? – user145400 2014-09-18 15:55:46