
Java
CSS:#contAIner{ padding: 10px;}#txt1{ position: ABSolute; top: 0; left: 0;}#txt2{ position: ABSolute; top: 0; right: 0;}#txt3{ position: ABSolute; bottom: 0; right: 0;}JavaScript:var contAIner = document.getElementById("contAIner");var txt1 = document.getElementById("txt1");var txt2 = document.getElementById("txt2");var txt3 = document.getElementById("txt3");var line = document.createElement("div");line.style.backgroundColor = "#ccc";line.style.width = "100%";line.style.height = "2px";contAIner.appendChild(line);// 给第一个文本框添加连接线var x1,y1 = txt1.offsetLeft,txt1.offsetTop;var x2,y2 = txt2.offsetLeft,txt2.offsetTop;var x3,y3 = txt3.offsetLeft,txt3.offsetTop;var line1 = document.createElement("div");line1.style.backgroundColor = "#ccc";line1.style.width = "100%";line1.style.height = "2px";line1.style.left = x1+10+ "px";line1.style.top = y1 + "px";// 给第二个文本框添加连接线var line2 = document.createElement("div");line2.style.backgroundColor = "#ccc";line2.style.width = "100%";line2.style.height = "2px";line2.style.left = x2+10 + "px";line2.style.top = y2 + "px";// 给第三个文本框添加连接线var line3 = document.createElement("div");line3.style.backgroundColor = "#ccc";line3.style.width = "100%";line3.style.height = "2px";line3.style.left = x3+10 + "px";line3.style.top = y3 + "px";// 将三个文本框的连接线都添加到容器内contAIner.appendChild(line1);contAIner.appendChild(line2);contAIner.appendChild(line3);以上代码实现了将多个文本框连接起来的效果。可以根据需要进行调整和扩展。Copyright © 2025 IZhiDa.com All Rights Reserved.
知答 版权所有 粤ICP备2023042255号