如何在iframe src中使用javascript变量

Joh*_*nny 5 html javascript iframe adp

如何在iframe src中编写javascript变量?

喜欢

<iframe id="showskill" scrolling="yes" height="350" width ="350" src="http://localhost/POSkill/skillshow.aspx?user_id="+ ReturnURL() ></iframe>
Run Code Online (Sandbox Code Playgroud)

这里的ReturnURL()是一个返回值的javascript函数.但问题是iframe源我没有得到函数的返回值.我没有采用正确的格式或遗漏某些东西吗?

在此先感谢约翰尼

nnn*_*nnn 17

您不能以这种方式直接在html标记中使用JavaScript变量或函数.你可以做的是先定义你的iframe,然后从JavaScript设置它的来源:

<iframe id="showskill" scrolling="yes" height="350" width ="350" src=""></iframe>

<script>
    document.getElementById("showskill").src =
              "http://localhost/POSkill/skillshow.aspx?user_id="+ ReturnURL();
</script>
Run Code Online (Sandbox Code Playgroud)

还有其他几种方法可以实现类似的功能,但是当我不确定你的上下文是什么时,我真的不想完全了解它们.