嗨,我是JavaScript新手,看起來似乎無法解決我的問題。 我正在尋求向用戶提供一個圖像的網址,並將其添加到使用html和另一個js文檔製作的圖庫。畫廊很好,只需要找出一種方法來添加一個新的img標籤與其中的網址。使用js將圖片從網址添加到圖片庫html使用js
這是我到目前爲止有:
function getUrl() {
var url = prompt('Enter image URL');
if (url) { // Do string and URL validation here and also for image type
return url;
} else {
return getUrl();
}`.slider image.src = getUrl();`
<form action="" method="post" class="contact" id="contact" onsubmit="return getUrl()">
<label for="name">Add Image url:</label>
<input type="submit" value="submit">
</form>
<div class="slider">
<img src="gallery/img1.jpg" alt="image 1" />
<img src="gallery/img2.jpg" alt="image 2" />
<img src="gallery/img3.jpg" alt="image 3" />
<img id="image"/>
<button class="prev"><</button>
<button class="next">></button>
</div>
如果你能幫助無論如何這將是巨大的,謝謝。
編輯:我的問題是我想添加img標籤到一個已經在html代碼中的圖庫,但沒有改變任何已經存在的照片的src,只是添加標籤,每次添加照片時的url照片。
[未經jQuery的JavaScript的變化IMG SRC屬性]的可能的複製(http://stackoverflow.com/questions/9731728/javascript-change-img-src-attribute-without-jquery) –
不要惡意破壞你的帖子。 –