开发者

How to register HTML text with DOM?

I get 开发者_如何学运维following text from the as a result of a AJAX request.

<div class="selectMe" >
    <select name="clientAcc" id="clientAcc" style="width: 144px;" >
         <option>JOHN</option>
         <option selected="selected">BOB</option>
    </select>
</div>

what i want to do is register this node in HTML DOM and access the select component as document.getElementById("clientAcc"). I dont know how to do this? can some one please help me. thanks in advance


Example

var data = <div class="selectMe"> //... plug your ajax response here,
    myDiv  = document.createElement('div');
myDiv.id = 'divClientAcc';
myDiv.innerHTML = data;
document.body.appendChild(myDiv);

Do note that you cannot have two elements with the same id (clientAcc). You'll have to change/drop the id of the inner select or the appended div.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜