gpt4 book ai didi

Javascript 交换三段

转载 作者:行者123 更新时间:2023-12-02 13:56:05 26 4
gpt4 key购买 nike

嗨,我的交换功能没有按预期正常工作,我错过了什么,我似乎找不到问题,请参见下文。预先感谢您!

<html>
<head>
<title>Three Pharagraphs</title>
<script>
function swap(a,b) {
var c = a.innerHTML;
a.innerHTML = b.innerHTML;
b.innerHTML = c;
}
window.onload = function() {
var link1 = document.getElementById('link1.1');
var link2 = document.getElementById('link2.2');
var link3 = document.getElementById('link3.3');
var p1 = document.getElementById('line1');
var p2 = document.getElementById('line2');
var p3 = document.getElementById('line3');
link1.onclick = swap(p1,p3);
link2.onclick = swap(p2,p3);
link3.onclick = swap(p1,p3);
}
</script>
</head>
<body>
<p id="line1">What is Lorem Ipsum?</p>
<p id="line2">Why do we use it?</p>
<p id="line3">The standard Lorem Ipsum passage.</p>
<p><a href="#" id="link1.1">1<->2</a> <a href="#" id="link2.2">2<->3</a><a href="#" id="link3.3">3<->1</a>
</body>
</html>

最佳答案

像这样更改 link1,2 和 3 onclick 函数:

        link1.onclick = function() {
swap(p1,p3);
}
link2.onclick = function() {
swap(p2,p3);
}
link3.onclick = function() {
swap(p1,p3);
}

关于Javascript 交换三段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40678919/

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