1
對於我的網站,我創建了一個隨機顯示圖像和相關文本的數組。我已經獲得了該陣列的工作,但第一行文本從右下角或圖像開始。如何讓圖像左移,文字從圖像的頂部開始?Javascript圖像和文本數組格式化
var r_text = new Array();
r_text[0] = "<em>Adrian's online program is totally unique and his approach is founded on the principle that your career should really just be another way to express yourself. I am deeply grateful to have found a more fitting career in brand management and I hope to start a business down the road.</em><br>Matt, San Francisco";
r_text[1] = "<em>I can tell you that after 3+ months using this career pathfinding program that my career outlook has never been better! I am currently going through a complete career change that I would have never dreamed about before I started this program. </em><br>Conrad, San Francisco";
var random_img = new Array();
random_img[0] = '<img src="http://lorempixel.com/100/100/nature/1">';
random_img[1] = '<img src="http://lorempixel.com/100/100/nature/2">';
var total_testimonials = 2;
var random_number = Math.floor((Math.random()*total_testimonials));
document.write(random_img[random_number]);
document.write(r_text[random_number]);
你的意思是像CSS的'浮動:左;'? – Xufox
這真的不是一個JavaScript問題;它關於HTML和CSS。請重新編寫您的問題,重點關注這些問題。 –
'document.write'和'new Array'在JavaScript中都是非常糟糕的做法。考慮使用'document.createElement'(加上它附加到DOM),並簡單地'var foo = []'。 –