gpt4 book ai didi

javascript - 如何通过 javascript 将较小的框插入表单框?

转载 作者:行者123 更新时间:2023-12-03 04:34:13 25 4
gpt4 key购买 nike

这就是我所拥有的:

enter image description here

这就是我想要的:

enter image description here

我尝试使用 html-tables,但我无法获得正确的比例,最终得到如下结果:

enter image description here

所以我觉得我需要使用JS将框插入到现有的表单框中。感谢任何对我如何实现这一目标的指示。

最佳答案

下面的代码将在1秒后添加前缀

function addPrefix() {
var newNode = document.createElement("div");
var newContent = document.createTextNode("+1");
newNode.appendChild(newContent);
newNode.style.cssText = "border: 1px solid blue; box-sizing: border-box;height: 30px; line-height: 30px; float: left"

var targetDiv = document.getElementById("phone");
var parentDiv = targetDiv.parentNode;

parentDiv.insertBefore(newNode, targetDiv);
}

setTimeout(addPrefix, 1000);
#phone{
height: 30px;
box-sizing: border-box;
}
<form id="myForm">
<input type="text" name="phone" id="phone" placeholder="Mobile or email" />
</form>

关于javascript - 如何通过 javascript 将较小的框插入表单框?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43356510/

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