2013-02-27 51 views
0

我想顯示立方體下方的文本....代碼工作正常,當我在小提琴單獨工作.... 但是當我把它放在它不工作我工程.... 你能告訴我如何顯示數據文本= 「Cube1」值.....從數據文本顯示數據屬性

工作代碼http://jsfiddle.net/PKwDp/4/

不工作密碼http://jsfiddle.net/rajkumart08/EDKkg/1/

$('document').ready(function() { 
      window.setTimeout(function() { 
       $('.cubeCell').each(function() { 
        var htmlText = $(this).attr('data-text'); 
        $(this).append('<div class="cubeTextStyle">'+htmlText+'</div>'); 
       }); 
      }, 600); 

     }); 


<div data-text="Cube1" data-caption="&lt;a style='margin-left: 92px; font-size: 18px; color: grey;' href='http://www.w3schools.com/' &gt;Create&lt;/a&gt; &lt;div&gt; &lt;a style='margin-left: 92px; font-size: 18px; color: grey;' &gt;View/Edit&lt;/a&gt; &lt;/div&gt; &lt;a style='margin-left: 92px; font-size: 18px; color: grey;' &gt;Labels&lt;/a&gt;" data-image="http://www.defie.co/designerImages/inventoryControl.png">testing</div> 
+0

沒有'.cubeCell'元素 - > [** ** FIDDLE(http://jsfiddle.net/EDKkg/2/),因此循環永遠不會運行? – adeneo 2013-02-27 21:37:22

+0

jsfiddle.net/rajkumart08/EDKkg/3我更新的類,但仍然沒有工作 – user2045025 2013-02-27 21:47:52

回答

1

的問題在你的(非工作)的例子是具有data-text屬性的元素沒有一個cubeCell類。

這是你在你的jsfiddle有HTML:

<div data-text="Cube1" data-caption="&lt;a style='margin-left: 92px; font-size: 18px; color: grey;' href='http://www.w3schools.com/' &gt;Create&lt;/a&gt; &lt;div&gt; &lt;a style='margin-left: 92px; font-size: 18px; color: grey;' &gt;View/Edit&lt;/a&gt; &lt;/div&gt; &lt;a style='margin-left: 92px; font-size: 18px; color: grey;' &gt;Labels&lt;/a&gt;" data-image="http://www.defie.co/designerImages/inventoryControl.png">testing</div> 

編輯:

後您更新到的jsfiddle,文現在正在正確添加。但是,您看不到它,因爲它隱藏在立方體本身之後。但是現在這是一個CSS問題,因爲你的CSS與實際例子完全不同。

編輯2:

你缺少了div.cubeTextStyle的CSS。你的工作示例有它:

div.cubeTextStyle { 
    position: relative; 
    top: 105px; 
    background: none !important; 
    color: #333 !important; 
    border: none !important; 
    box-shadow: none !important; 
    -webkit-box-shadow: none !important; 
} 
+0

http://jsfiddle.net/rajkumart08/EDKkg/3/我更新的類,但仍然沒有工作 – user2045025 2013-02-27 21:47:22

+0

你究竟做任何調試?如果您檢查'cubeTextStyle'元素,則文本現在已被正確添加。你只是在預覽中看不到它,因爲「測試」文本是阻礙的。 – Steve 2013-02-27 21:53:31

+0

你能告訴我在哪裏可以調整的CSS ...我做到了,但無法找到它...... – user2045025 2013-02-27 22:11:37

0

我相信你使用的數據屬性如下:

$(this).data('text').val() 
+0

我同意,這是更好的辦法......不過,OP的做法應該工作了。 – Steve 2013-02-27 21:35:31

+0

jsfiddle.net/rajkumart08/EDKkg/3我更新的類,但仍然沒有工作 – user2045025 2013-02-27 21:48:16