JavaScript HTML转义按钮(JavaScript HTML escape button)

编程入门 行业动态 更新时间:2024-10-26 11:30:27
JavaScript HTML转义按钮(JavaScript HTML escape button)

我正在尝试创建一个按钮,将我的链接编码为ascii,而不是单击将我重定向到新的编码地址。

我已经有了编码部分,但按钮只是在点击时显示转换后的代码。 我想改为将我重定向到那个编码页面。

<body> <p>Click the button to encode a URI.</p> <button onclick="myFunction()">Try it</button> <p id="demo"></p> <script> function myFunction() { var uri = "https://webpage.com/submit.do?firstName=Ždžrgr&lastName=Žrđredj&phone=(24324) 09942&email=email@email.net”; var res = encodeURI(uri); document.getElementById("demo").innerHTML = res; } </script> </body>

有人可以帮我这个吗? 我是JavaScript的新手。

I am trying to make a button which would encode my link into ascii and than on click redirect me to that new encoded address.

I already have the encoding part but the button just displays the converted code on click. I would like it instead to redirect me to that encoded page.

<body> <p>Click the button to encode a URI.</p> <button onclick="myFunction()">Try it</button> <p id="demo"></p> <script> function myFunction() { var uri = "https://webpage.com/submit.do?firstName=Ždžrgr&lastName=Žrđredj&phone=(24324) 09942&email=email@email.net”; var res = encodeURI(uri); document.getElementById("demo").innerHTML = res; } </script> </body>

Can someone please help me with this? I am new to JavaScript.

最满意答案

您可以使用location.href重定向页面。 getElementById()从页面获取具有id的元素,以获取或设置当前值。

function myFunction() { var uri = "https://webpage.com/submit.do?firstName=Ždžrgr&lastName=Žrđredj&phone=(24324) 09942&email=email@email.net"; var res = encodeURI(uri); location.href = res; }

You can use location.href to redirect the page. getElementById() gets the element with id inside the paranthesis from the page for getting or setting the current value.

function myFunction() { var uri = "https://webpage.com/submit.do?firstName=Ždžrgr&lastName=Žrđredj&phone=(24324) 09942&email=email@email.net"; var res = encodeURI(uri); location.href = res; }

更多推荐

本文发布于:2023-07-24 08:02:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1243459.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:按钮   HTML   JavaScript   escape   button

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!