英文:
How to pass javascript variable into another place?
问题
你好,以下是您要翻译的内容:
<div id="res">
<script>
var url_string = window.location.href; //window.location.href
var url = new URL(url_string);
var c = url.searchParams.get("x");
console.log(c);
adUnit = document.getElementById("res");
adUnit.innerHTML = '<ins ve-id="如何传递变量 c 在这里..?"></ins>';
</script>
<script src="//net.my.com/js.php"></script>
希望这对您有所帮助。
英文:
hello i am trying to pass javascript var can anyone explain how to do it ..?
<div id="res">
<script>
var url_string = window.location.href; //window.location.href
var url = new URL(url_string);
var c = url.searchParams.get("x");
console.log(c);
adUnit = document.getElementById("res");
adUnit.innerHTML = '<ins ve-id="how to pass var c here..?"></ins>';
</script>
<script src="//net.my.com/js.php"></script>
答案1
得分: 1
以下是翻译好的部分:
在下面的方式中,您可以这样做:
adUnit.innerHTML = ''<ins ve-id="' + c + '"></ins>'';
在ES6版本中:
adUnit.innerHTML = <ins ve-id="${c}"></ins>
;
英文:
You can do it like below
adUnit.innerHTML = '<ins ve-id="' + c + '"></ins>';
In ES6 version
adUnit.innerHTML = `<ins ve-id="${c}"></ins>`;
答案2
得分: 1
以下是翻译好的代码部分:
<div id="res">
<script>
var url_string = window.location.href; //window.location.href
var url = new URL(url_string);
var c = url.searchParams.get("x");
console.log(c);
adUnit = document.getElementById("res");
adUnit.innerHTML = '<ins ve-id="' + c + '"></ins>';
</script>
<script src="//net.my.com/js.php"></script>
adUnit.innerHTML = `<ins ve-id="${c}"></ins>`;
希望这些翻译对您有帮助。
英文:
You can try the following:
<div id="res">
<script>
var url_string = window.location.href; //window.location.href
var url = new URL(url_string);
var c = url.searchParams.get("x");
console.log(c);
adUnit = document.getElementById("res");
adUnit.innerHTML = '<ins ve-id="' + c + '"></ins>';
</script>
<script src="//net.my.com/js.php"></script>
You can also take a look on template literals
adUnit.innerHTML = `<ins ve-id="${c}"></ins>`;
答案3
得分: 0
你可以使用插值字符串。
所以,像这样做:
adUnit.innerHTML = <ins ve-id=4{c}></ins>
;
英文:
You can use interpolate string.
So, do something like
adUnit.innerHTML = <ins ve-id=4{c}></ins>
;
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论