使用Javascript来添加HTML? [英] Using Javascript to add HTML?

查看:92
本文介绍了使用Javascript来添加HTML?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



这是因为事实上,有一定的DIV可以让Javascript写一些HTML到页面中。我无法访问标记的网站区域。但我想在那里添加一个小节。



例如,我想添加一些html的容器是
div id = topic>< / em> / div>



是否有可能让Javascript执行此操作
< * div id =topics >< div id =mysection>< / em> / div>< * / div>

非常感谢!

解决方案

即使使用普通的JavaScript,这也相当容易实现。

  var topicsDiv = document.getElementById(topics); 
topicsDiv.innerHTML ='< div id =mysection> < / DIV>;

如果您要做一些严重的DOM(文档对象模型,即HTML结构)操作但是,我建议你考虑使用 JQuery 库。但是,如果任务仅限于您的问题,那么普通的JavaScript应该没问题,如上所示。


I was wondering if it was possible to get Javascript to write some HTML onto the page in a certain DIV.

This is due to the fact, there are certain areas of the site where i don't have access to the markup. But i would like to add a small section there.

For example the container i want to add some html to is <div id="topics"></div>

Is it possible to get Javascript to do this <*div id="topics"> <div id="mysection"> </div> <*/div>

Many thanks!

解决方案

This is fairly simple to do, even using plain JavaScript.

var topicsDiv = document.getElementById("topics");
topicsDiv.innerHTML = '<div id="mysection"> </div>';

If you're going to be doing some serious DOM (Document Object Model, i.e. HTML structure) manipulation, however, then I would recommend you look into using the JQuery library. Yet if the task is limited to your question, then normal JavaScript should be fine, as shown above.

这篇关于使用Javascript来添加HTML?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆