【发布时间】:2016-10-20 21:45:41
【问题描述】:
我正在尝试从动态更改并存储在值 c 中的数组中获取文件路径。当我单击激活它的按钮时,它会返回文件在数组 exp 中的编号的网址。我想要 www.anon-curb.com/swfs/exampleflash.swf 但它给了我 www.anon-curb.com/swfs/464 ;464 是它在数组中的顺序。
HTML
<div class="share_con">
<button id="share">Get a link!</button>
<textarea id="link"></textarea>
</div>
JAVASCRIPT
var c = sessionStorage.getItem('order');
sessionStorage.setItem('order', c);
var flashcon, test, temp;
share = document.getElementById('share');
link = document.getElementById('link');
function init() {
share.onclick = function () {
console.log('Event: share button clicked');
shareshare();
}
}
function shareshare() {
console.log('Called: shareshare()');
link.innerHTML = 'www.anon-curb.com/' + c;
}
// What displays the actual flash and title for the flash
function displayFiles() {
console.log('Called: displayFiles()');
test = paths[c].substring(paths[c].lastIndexOf('.') + 1, paths[c].length);
document.getElementById('title').innerHTML = displaytext[c];
flashcon.innerHTML =
'<object id="flashcontent" data="' + paths[c] + '">' +
'<param name="movie" type="application/x-shockwave-flash">' +
'</object>';
}
window.addEventListener ?
window.addEventListener('load', init, false) :
window.attachEvent('onload', init);
});
所有变量都被正确创建和调用我唯一的问题是我不知道如何获取数组中包含的实际文本而不是它的输入顺序。
【问题讨论】:
-
您的数组可引用为什么?使用括号表示法
arr[c] -
我提供了更多我认为会有所帮助的 JavaScript 代码
-
你能给我们调试一下你的
sessionStorage吗? -
你可能想做
link.innerHTML = 'www.anon-curb.com/' + paths[c];而不是link.innerHTML = 'www.anon-curb.com/' + c;。你没有提供你定义paths的代码,但是看看你是怎么用的,我想这就是你需要的吗? -
天啊...伙计,我刚刚将其发布为我的答案,但当我这样做时页面没有更新....
标签: javascript jquery arrays html