Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/85.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在javascript中从数组中获取文本并将其附加到文本区域?_Javascript_Jquery_Arrays_Html - Fatal编程技术网

如何在javascript中从数组中获取文本并将其附加到文本区域?

如何在javascript中从数组中获取文本并将其附加到文本区域?,javascript,jquery,arrays,html,Javascript,Jquery,Arrays,Html,我试图从一个动态变化并存储在值c中的数组中获取文件路径。当我点击激活它的按钮时,它返回的网址是文件在数组exp中的编号。我想要www.anon-curb.com/swfs/exampleflash.swf,但它给了我www.anon-curb.com/swfs/464;464是它在数组中的顺序 HTML 获取链接! JAVASCRIPT var c = sessionStorage.getItem('order'); sessionStorage.setItem('order

我试图从一个动态变化并存储在值c中的数组中获取文件路径。当我点击激活它的按钮时,它返回的网址是文件在数组exp中的编号。我想要www.anon-curb.com/swfs/exampleflash.swf,但它给了我www.anon-curb.com/swfs/464;464是它在数组中的顺序

HTML


获取链接!
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);
});
var c=sessionStorage.getItem('order');
sessionStorage.setItem('order',c);
var flashcon,测试,温度;
share=document.getElementById('share');
link=document.getElementById('link');
函数init(){
share.onclick=函数(){
log('Event:share button clicked');
shareshare();
}
}
函数shareshare(){
log('Called:shareshare()');
link.innerHTML='www.anon-curb.com/'+c;
}
//什么显示实际的闪光灯和闪光灯的标题
函数displayFiles(){
log('Called:displayFiles()');
测试=路径[c]。子字符串(路径[c]。lastIndexOf('..')+1,路径[c]。长度);
document.getElementById('title').innerHTML=displaytext[c];
flashcon.innerHTML=
'' +
'' +
'';
}
window.addEventListener?
window.addEventListener('load',init,false):
window.attachEvent('onload',init);
});

所有变量都被正确地创建和调用我唯一的问题是我不知道如何获取数组中包含的实际文本,而不是它的顺序。

所以我做了一些修改,我想“我太笨了!!!为什么我不使用c的数字来调用数组中的文本?”所以我就是这么做的

function shareshare() {
        var l = paths[c];
        console.log('Called: shareshare()');
        link.innerHTML = 'www.anon-curb.com/' + l;
    }

顺便说一句,我不知道为什么我没有立即想到这一点。当我查看您的代码时,我发现了一些问题:

  • 文本区域使用
    innerText
    ,而不是
    innerHTML

    这是一个简单的解决方案,只需在
    shareshare

    function shareshare() {
      console.log('Called: shareshare()');
      link.innerText = 'www.anon-curb.com/' + c;
    }
    
  • 还要注意您的解决方案:

    function shareshare() {
        var l = paths[c];
        console.log('Called: shareshare()');
        link.innerHTML = 'www.anon-curb.com/' + l;
    }
    

    希望我能有所帮助(即使你已经弄明白了)

    你的数组可引用为什么?使用括号表示法
    arr[c]
    我提供了更多我认为会有帮助的JavaScript代码,你能给我们调试一下你的
    会话存储吗
    而不是
    link.innerHTML='www.anon-curb.com/'+c。您没有提供定义路径的代码,但看看您是如何使用它的,我想这就是您需要的?天哪。。。哥们,我只是把它作为我的答案发布了出来,而我发布的时候页面没有更新……是的,这就是我在你发布这篇文章前2分钟的评论中所建议的。耶,我知道,但我没有更新页面,因为我在选择它的时候向下滚动了,所以我没有看到这没有问题。最重要的是你得到了一个解决方案:)我感谢你的回答,但innerHTML工作得很好:嗯。在我的Chrome(51)版本中,它不起作用,根据我从规范中读到的内容,
    innerText
    是使用的方法。直到,猜猜!
    function shareshare() {
        var l = paths[c];
        console.log('Called: shareshare()');
        link.innerHTML = 'www.anon-curb.com/' + l;
    }