开发者

how to add textbox in table using javascript?

I just want to add a textbox in table at runtime using javascript.开发者_Go百科 Anybody know...?

thanks.


Wow holy moly what's with all the JQuery answers.

There are two ways of doing this:

Appending item to the DOM

This is probably the best way:

var input = document.createElement("input"); 
input.type = "text"; 
container.appendChild(input);

InnerHTML

This is not such a good method, innerHTML is dubious from a standards perspective. I would highly recommend using the DOM method above, but here is an alternative:

document.getElementById("containerDiv").innerHTML += "<input type='text' />";


Hope this source code will guide you through the point which you are looking for !

tableWidget = new YK.TableFactory(3,5,false, false);

textbox = new YK.Entry();

tableWidget.attach(
  textbox, 
  0, 1, 0, 1, 
  {align: YK.JUSTIFY_LEFT, fill: true}, 
  {align: YK.JUSTIFY_TOP, fill: true}, 
  1, 1

);


This will insert a textarea to the first td of the first tr of the first table on a page (using jQuery). But i guess it will send you on the right way

$('table:first tr:first td:first').append('<textarea>my text</textarea>');


Using jQuery you can do like this:

$('<input type="text" name="" id="" />').appendTo('#id_of_my_td');
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜