Javascript 显示数据文本属性中的数据
我试图在立方体下方显示一个文本…当我独自在小提琴中工作时,代码工作正常。。。。 但当我把它放在我的项目中时,它就不起作用了。。。。 您能告诉我如何显示数据text=“Cube1”值 工作代码 非工作代码Javascript 显示数据文本属性中的数据,javascript,jquery,jquery-ui,css,javascript-events,Javascript,Jquery,Jquery Ui,Css,Javascript Events,我试图在立方体下方显示一个文本…当我独自在小提琴中工作时,代码工作正常。。。。 但当我把它放在我的项目中时,它就不起作用了。。。。 您能告诉我如何显示数据text=“Cube1”值 工作代码 非工作代码 $('document').ready(函数(){ setTimeout(函数(){ $('.cubeCell')。每个(函数(){ var htmlText=$(this.attr('data-text'); $(this.append(“”+htmlText+“”); }); }, 600)
$('document').ready(函数(){
setTimeout(函数(){
$('.cubeCell')。每个(函数(){
var htmlText=$(this.attr('data-text');
$(this.append(“”+htmlText+“”);
});
}, 600);
});
测试
我相信您使用的数据属性如下:
$(this).data('text').val()
(非工作)示例中的问题是,具有数据文本
属性的元素没有cubeCell
类
这是JSFIDLE中的HTML:
<div data-text="Cube1" data-caption="<a style='margin-left: 92px; font-size: 18px; color: grey;' href='http://www.w3schools.com/' >Create</a> <div> <a style='margin-left: 92px; font-size: 18px; color: grey;' >View/Edit</a> </div> <a style='margin-left: 92px; font-size: 18px; color: grey;' >Labels</a>" data-image="http://www.defie.co/designerImages/inventoryControl.png">testing</div>
我同意,这是更好的方式。。。但是,OP的方法也应该有效。jsfiddle.net/rajkumart08/EDKkg/3我更新了类但仍然不工作没有
.cubeCell
元素->,所以循环永远不会运行?jsfiddle.net/rajkumart08/EDKkg/3我更新了类但仍然不工作我更新了类但仍然不工作你真的做过任何调试吗?如果检查cubeTextStyle
元素,则现在已正确追加文本。你只是在预览中看不到它,因为“测试”文本挡住了你的去路。至少,你似乎缺少了div.cubeTextStyle
的CSS,它至少需要位置:相对;顶部:105px代码>以像其他示例一样工作。
<div data-text="Cube1" data-caption="<a style='margin-left: 92px; font-size: 18px; color: grey;' href='http://www.w3schools.com/' >Create</a> <div> <a style='margin-left: 92px; font-size: 18px; color: grey;' >View/Edit</a> </div> <a style='margin-left: 92px; font-size: 18px; color: grey;' >Labels</a>" data-image="http://www.defie.co/designerImages/inventoryControl.png">testing</div>
div.cubeTextStyle {
position: relative;
top: 105px;
background: none !important;
color: #333 !important;
border: none !important;
box-shadow: none !important;
-webkit-box-shadow: none !important;
}