开发者

How to space my checkboxes and the text associated with them

开发者 https://www.devze.com 2023-02-22 19:11 出处:网络
I have these check boxes that are created with a javascript function: I would like the text to appear to the right of the checkbox and all of the text to be on one line.

I have these check boxes that are created with a javascript function:

How to space my checkboxes and the text associated with them

I would like the text to appear to the right of the checkbox and all of the text to be on one line.

Here is the javascript function and the html:

function receiveAnswer(response) {
//  var aSeats = document.getElementById("aSeats");
//    aSeats.options.length = 0;// clear it out
//
//   for (var i = 0; i < response.aSeats.length; i++) { // add the items back in
//    var option = aSeats.appendChild(document.createElement("option"));
//    option.value = i;
//    option.appendChild(document.createTextNode(response.aSeats[i]));
//  }

  var aSeats = document.getElementById("aSeats");
    while (aSeats.childNodes.length > 0) { // clear it out
    aSeats.removeChild(aSeats.childNodes[0]);
  }

   for (var i = 0; i < response.aSeats.length; i++) { // add the items back in
    var input = aSeats.appendChild(document.createElement("input"));
    input.value = i;
    input.type = "checkbox";
    var br = aSeats.appendChild(document.createElement("br"));
    input.appendChild(document.createTextNode(response.aSeats[i]));
    var br = aSeats.appendChild(document.createElement("br"));
    var br = aSeats.appendChild(document.createElement("br"));
    var br = aSeats.appendChild(document.createElement("br"));
    var br = aSeats.appendChild(document.createElement("br"));
    var br =开发者_如何转开发 aSeats.appendChild(document.createElement("br"));
  }
}

html code:

<div name="aSeats" id="aSeats">
    <input type="checkbox">
</div>


Why not use jQuery.

Check working example http://jsfiddle.net/FxgYz/


Create a separate div to put the text in and position that div to the side of the input box, something like:

var div = document.createElement("div");
div.style.width = 100;
div.innerHTML = text;
etc.
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号