gpt4 book ai didi

javascript - 从同一网站的外部页面加载内容到 div

转载 作者:行者123 更新时间:2023-11-29 20:01:57 27 4
gpt4 key购买 nike

我尝试根据选择框中的选择将内容加载到 Intex 中的 div。它不起作用,所以出了点问题。我做了一个四页的例子来展示它的基本情况:

Index.html
one.html
two.html
three.html

在索引中,我有一个 ID 为“selectchoice”的选择元素:

<select id="selectchoice>
<option>Select a choice</option>
<option>1</option>
<option>2</option>
<option>3</option>
</select>

我在索引中也有一个 id 为“get_content”的 div:

<div id="get_content"></div>

当我将选择元素更改为选项 1 或 2 或 3 时,我想将 one.html 或 two.html 或 three.html 加载到 div get_content 中。

然后我将这段代码放在 if Index.html 的标题中,在 jQuery 文件链接之后。

<script>
$("#selectchoice").change(function(){
$("#get_content").load("");
$("#get_content").load("one.html");
$("#get_content").load("two.html");
$("#get_content").load("three.html");
});

然后我运行该站点(在具有在同一站点上运行的其他加载脚本的服务器上),但它不工作。怎么了? :/

脚本和编程有点新,所以如果有任何标准错误,请不要感到惊讶。

有人发现错误吗?

最佳答案

首先应该关闭 select 标签的 id 属性,并且优化你的 javascript 函数。有点像

<script>
$("#selectchoice").change(function(){
var page = this.selectedIndex;
if(page == 1) {
$("#get_content").load("one.html");
return;
}
else if(page == 2) {
$("#get_content").load("two.html");
return;
}
....
});

关于javascript - 从同一网站的外部页面加载内容到 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13953700/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com