我正在尝试将 window.location.path 名称附加到源中,但目前它没有返回该值。我附加的正确吗?
<script src="abc.com/gethistory?product=aj1&m=abn&lang='"+ window.location.pathname.substring(1,2)" ></script>
最佳答案
JavaScript 不在 HTML 标记中执行。您需要编写一个脚本来使用计算出的 URL 创建标记。
var script = document.createElement("script");
script.src = "abc.com/gethistory?product=aj1&m=abn&lang="+ window.location.pathname.substring(1,2)";
document.head.appendChild(script);
关于javascript - 在 src 中附加 window.location,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58420201/