如何在输入标记旁边添加div

时间:2017-11-02 07:25:12

标签: javascript html css

我有一个我这样创建的输入字段。

var inputVal = document.createElement("input");

inputVal.setAttribute("type", "checkbox");
inputChek.onchange = select;
inputChek.setAttribute("value", title);

//inputChek.after(sortDiv);
docClass.prepend(inputChek);
docClass.append(newDiv);

我想在文本之后添加带箭头图像的div,但它没有显示。 div正在创造,但它正在下降。

var newDiv = document.createElement("div");

newDiv.setAttribute("class", "Arrow");
//sortDiv.style.display = ' transform: rotate(45deg), webkit-transform: rotate(45deg);'*/
newDiv.setAttribute("onclick",'divClick("title")');
newDiv.style.background = "red";
newDiv.style.width = "10px";
newDiv.style.height = "10px";

这是图像。

我想在文字后添加。 enter image description here 任何解决方案。

1 个答案:

答案 0 :(得分:0)

以下是输入后如何添加div元素的基本示例,
您可以根据需要修改(和样式):



var root = document.getElementById("root"),
    checkbox = document.createElement("input"),
    block = document.createElement("div");

checkbox.type = "checkbox";
checkbox.value = "title";

block.className = "arrow";
block.setAttribute("onclick",'divClick("title")');
block.style.background = "red";
block.style.display = "inline-block";
block.style.width = "36px";
block.style.height = "12px";

root.appendChild(checkbox);
root.appendChild(block);

function divClick( text ){
  console.log('you had just clicked the ' + text );
}

<div id="root" class="form-group"></div>
&#13;
&#13;
&#13;

相关问题