开发者

How to space my checkboxes and the text associated with them

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜