0
我想添加一個選項,供用戶上傳將顯示在頁面上的youtubelink。該腳本應該獲得textarea的.value,並將其發送到一個var數組的youtube鏈接。如何從用戶收集信息與<textarea> javascript並保存它? (網站用戶上傳信息)
代碼:
var array=["npvNPORFXpc", "CcsUYu0PVxY", "dE_XVl7fwBQ", "iIwxR6kjTfA", "USe6s2kfuWk"];
var iframe = document.getElementById('frame');
var previousRandom = "npvNPORFXpc"; // initial video
document.getElementById('random').addEventListener('click', function() {
do {
var random = array[Math.floor(Math.random() * array.length)];
} while (previousRandom === random)
var url="http://www.youtube.com/embed/"+random;
previousRandom = random;
iframe.src = url;});
document.getElementById('prevVideo').addEventListener('click', function() {
var curIndex = array.indexOf(previousRandom);
curIndex--;
if (curIndex < 0)
{
curIndex = array.length -1;
}
var video = array[curIndex];
var url="http://www.youtube.com/embed/"+video;
previousRandom = video;
iframe.src = url;
});
所以我想我的網站的用戶能夠添加YouTube網址至極腳本應該添加到VAR陣列。我不太瞭解JavaScript,但我一直在嘗試整夜,卻找不到它。
檢查出來:http://jsfiddle.net/KgJ9J/1/
希望有人能幫助我!
哎呀..所以它是不可能保存用戶數據沒有PHP?比我覺得我應該開始使用PHP以及任何您可以給我的例子/資源?像http://www.w3schools.com/php/php_ref_array.asp – user3375841
寫一個文件:http://us3.php.net/manual/en/function.file-put-contents.php 讀取文件:http ://www.php.net/manual/en/function.readfile.php 或者你可以使用一個數據庫(但你仍然需要通過PHP來訪問它) – Chrisi
感謝你不好意思看它,並可以回答一些問題之後:) – user3375841