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

标签 javascript html

这就是我所拥有的:

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/

相关文章:

javascript - DOM 中的动态 Unicode 生成

html - 不同设备底部的按钮组

php - 制作一个仪表板,显示具有延迟的 IP 列表

html - 具有完整性的异步 css

javascript - 如何从在 gulp-run 中执行的进程打印控制台消息?

javascript - JQuery:根据是/否输入更改选项文本

Javascript:如何使用参数在函数中使用对象属性?

html - 为什么@font-face 不工作

html - 如何在文本输入上方对齐按钮?

javascript - 如何在指令模板中将嵌入元素的范围更改为 ng-repeat 项范围