JavaScript密码+按钮打开目标元素中的URL

发布于 2025-01-20 06:28:32 字数 804 浏览 4 评论 0原文

我学会了如何使用密码和按钮打开链接。 我使用以下代码:

<input type="text" id="text" />
<input type="button" id="btn" value="Submit" onClick="window.location=url;" />

<script>
$("#btn").click(function() {
window.location="example.com/"+$("#text").val();})
</script>

我想弄清楚的是,我是否可以针对DIV元素以进行内部打开的链接。

我一直在使用以下脚本将html页面加载到带有链接的指定div元素中:

<div class="item1" id="pageone"></div>
<a href="" onclick="loadSAMEDiv1(); return false;">link</a>

<script>
function loadSAMEDiv1() { 
$.ajax({ 
 url: 'item1.html', 
 success: function(data) { 
      $('#pageone').html(data); 
 } 
 }); 
} 
</script>

我想我想知道是否有一种方法可以使第一个脚本在目标div中打开的密码URL,就像它一样在第二个脚本中。因此,当您单击按钮元素时,它将使用输入文本框中的密码将URL变为URL,然后将其加载到#PageOne之类的Div中。

I learned how to open a link using a password and button.
I used the following code:

<input type="text" id="text" />
<input type="button" id="btn" value="Submit" onClick="window.location=url;" />

<script>
$("#btn").click(function() {
window.location="example.com/"+$("#text").val();})
</script>

What I would like to figure out is whether I can target a div element for the link to open within.

I've been using the following script to load html pages into a specified div element with a link:

<div class="item1" id="pageone"></div>
<a href="" onclick="loadSAMEDiv1(); return false;">link</a>

<script>
function loadSAMEDiv1() { 
$.ajax({ 
 url: 'item1.html', 
 success: function(data) { 
      $('#pageone').html(data); 
 } 
 }); 
} 
</script>

I guess I'm wondering if there's a way to make the password url made by the first script open in a targeted div, like it does in the second script. So when you click the button element it will make the url using the password entered into the text box and load it into a div like #pageone.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

丿*梦醉红颜 2025-01-27 06:28:32

最简单的方法是使用 Ajax load()。试试这个。

<input type="text" id="text" />
<input type="button" id="btn" value="Submit"/>

<div class="item1" id="pageone"></div>

<script>
    $("#btn").on("click", function() {
        $("#pageone").load("example.com/"+$("#text").val());
    });
</script>

The simplest way to do this is with Ajax load(). Try this.

<input type="text" id="text" />
<input type="button" id="btn" value="Submit"/>

<div class="item1" id="pageone"></div>

<script>
    $("#btn").on("click", function() {
        $("#pageone").load("example.com/"+$("#text").val());
    });
</script>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文