使用Javascript动态添加HTML元素

编程入门 行业动态 更新时间:2024-10-24 15:23:12
使用Javascript动态添加HTML元素 - textarea(Add HTML element - textarea dynamically using Javascript)

我知道可以使用Javascript动态地将HTML元素添加/删除到网页上。 我想知道以下可能 -

我的coldfusion网页有一个双列表格,表格的最后一行在第一列中有一个链接,第二列是空白的。 当用户点击那个链接时,textarea出现在第二列,到目前为止是空白的。

是否有可能使用Javascript来做到这一点? 我浏览了网络上的几个链接,并且像http://www.dustindiaz.com/add-and-remove-html-elements-dynamically-with-javascript/这样的一些指针确实有帮助,但似乎他们没有帮助我在我的场景。

我在这里先向您的帮助表示感谢。

I know it is possible to add/remove HTML elements dynamically to a web page using Javascript. I was wondering is the following possible-

My coldfusion web page has a two column table and the last row of the table has a link in the first column and the second column is blank. When user hits that link, a textarea shows up in the second column which was blank so far.

Is it possible to do this using Javascript? I went through a few links on the web and a few pointers like http://www.dustindiaz.com/add-and-remove-html-elements-dynamically-with-javascript/ did help but it seems they don't help me on my scenario.

Thanks for the help in advance.

最满意答案

对于您的场景,可能不需要添加元素。 您可以改为将元素加载到dom中(但隐藏),然后在点击链接时触发一些代码以显示它。 这个javascript很简单。

function ShowTextArea() { var ta = document.getElementById("textareaId"); ta.style = "display:inline"; }

For your scenario, it may not be necessary to add the element. You could instead have the element already loaded in the dom (but hidden), then fire some code to show it when the link is clicked. The javascript for that is quite simple.

function ShowTextArea() { var ta = document.getElementById("textareaId"); ta.style = "display:inline"; }

更多推荐

本文发布于:2023-07-22 19:28:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1222750.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:元素   动态   Javascript   HTML

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!