Closed. This question is off-topic。它当前不接受答案。
                            
                        
                    
                
            
                    
                
                        
                            
                        
                    
                        
                            想改善这个问题吗? Update the question,所以它是on-topic,用于堆栈溢出。
                        
                        2年前关闭。
                    
                
        

我正在创建一个名为test.html的html文件。
使用JavaScript,我已经解析了URL以获取解析的参数。

URL看起来像这样(示例URL)

http://path.to.a.webserver/test.html?p1=welcome&p2=home


解析值之后,我想将解析后的值以以下格式发送到HTML img标签。当我点击上述URL时,将解析值p1和p2,并执行test.html文件中的img标签。

<img src="http://example2.com/tiger.gif?p1={p1_parsed_value}&p2={p2_parsed_value}"


我尝试使用document.getElementById。我不确定是否正确。如何仅将那些已解析的URL值传递到img标签的src中?

最佳答案

var img = document.querySelector("img");//select node

img.setAttribute("src",url);//set src attribute to required url

10-07 12:24
查看更多