【问题标题】:Inject a button close to input box在输入框附近注入一个按钮
【发布时间】:2017-03-24 00:40:54
【问题描述】:
<input type="text"id="text111" name="text111">

我有这一行并试图在文本框的右侧注入一个按钮...请建议我如何在 JS 中做到这一点?

这是 chrome 的扩展
我将找到 ID 的每个实例并注入它......但是如何?

【问题讨论】:

  • 老实说,使用 HTML && CSS 是最简单的

标签: javascript button text inputbox


【解决方案1】:

使用.insertAdjacentHTML(),详情在Snippet中注释

片段

// Reference the textbox
var in111 = document.getElementById('text111');

/* use insertAdjecentHTML() method 
|| The first parameter is the position of insertion
|| The second parameter is the text that will be rendered into
|| HTML.
*/
in111.insertAdjacentHTML('afterend', '<button id="btn">Button</button>');
&lt;input type="text" id="text111" name="text111"&gt;

【讨论】:

    猜你喜欢
    • 2016-05-01
    • 2015-11-29
    • 2020-06-15
    • 1970-01-01
    • 1970-01-01
    • 2021-05-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多