Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/77.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_Html_Object - Fatal编程技术网

javascript中的对象文本到字符串

javascript中的对象文本到字符串,javascript,html,object,Javascript,Html,Object,尝试在多个页面上显示带有一些可重用代码的PDF 我有这个: <a href="http://somesite.com/someplace">click me</a> 然后我尝试稍后将该值粘贴到元素中,如下所示: myElement.src = 'http://docs.google.com/viewer?url=' + foo + '&embedded=true'; 因为foo是一个文本对象,所以它不起作用。当我硬编码时,它工作得很好,但我不想在网站上的每个页

尝试在多个页面上显示带有一些可重用代码的PDF

我有这个:

<a href="http://somesite.com/someplace">click me</a>
然后我尝试稍后将该值粘贴到元素中,如下所示:

myElement.src = 'http://docs.google.com/viewer?url=' + foo + '&embedded=true';
因为foo是一个文本对象,所以它不起作用。当我硬编码时,它工作得很好,但我不想在网站上的每个页面都硬编码。 当我将其登录到控制台时,我得到以下信息:

http://docs.google.com/viewer?url=[object%20Text]&embedded=true
我该怎么解决这个问题?我必须将foo转换为字符串吗?我该怎么做?

试试这个


myElement.src=http://docs.google.com/viewer?url=“+foo.nodeValue+”&embedded=true”

这里看起来不错:需要更多信息,这说明了什么?我不认为是链接DOM节点。另外,您不需要使用replace,您应该使用encodeURIComponentbar,因为它正是为此目的而构建的。这里涉及到一个onlick事件侦听器,this关键字指向a标记。我使用了encodeURIComponent,现在它可以工作了。。。我不明白,但我很高兴!
http://docs.google.com/viewer?url=[object%20Text]&embedded=true