var srcType = source.slice(source.lastIndexOf('.'));
//srcType = fileExtension
var imageFormats = ['.jpg','.png','.gif'],
videoFormats = ['.ogv','.png','.gif'];
// two lists, acceptable video/image types
var htmlSting = '';//initialize the htmlstring
if (srcType in imageFormats) //heres where my question is!!!
htmlString = '<img class="empty" id="it" src="'+source+'"> </img>';
else
htmlString = '<video class="empty" id="it" src="'+source+'" controls> </img>';
// these statements choose the proper media type.
好吧,所以繼承人:我正在編寫一些需要根據文件類型選擇html的東西。 有沒有辦法實現(imageFormats中的srcType)?這不起作用。我需要一個for循環嗎?我總是可以在html中使用或者是,但是當我們添加格式時,這將是詳盡無遺的。 我不喜歡for循環的原因是它在時間關鍵區域使用寶貴的時間。在in運算符中使用if語句
謝謝!我只是將數組放入一個對象中,工作正常:D –