使用DOM和javascript创建html代码 [英] Create html code using DOM and javascript
本文介绍了使用DOM和javascript创建html代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在按钮点击时使用javascript和jQuery创建一些代码,
这些代码看起来:
Hi, I want to create some code on button click using javascript and jQuery,
those code look:
<div class="news">
<img src="./images/1.jpg" />
<content>
<a class="person" href="">Lubomyr Pelyo</a>
<br />
<comment>
First record in news
</comment>
<br/>
<settings>
<a href="">Comment</a>
<a href="">Share</a>
<a href="">Remove</a>
</settings>
</content>
<br style="clear:both"/>
</div>
来创建我使用的代码:
to create thet code I use:
$('#newPost').click(function(){
var text = $('#new').val();
var textTrim = $.trim(text);
if(textTrim != ''){
var newsDiv = document.createElement('div');
newsDiv.setAttribute('class', 'news');
var person = document.createElement('img');
newsDiv.innerText = text;
$('#news').prepend(newsDiv);
}
$('#new').val('');
});
我无法找到如何用里面的所有块创建div .news。
I cant find how to create "div .news" with all those blocks inside.
推荐答案
(' #newPost')。click( function (){
var text =
('#newPost').click(function(){ var text =
(< span class =code-string>' #new')。val();
var textTrim =
('#new').val(); var textTrim =
.trim(text);
if (textTrim!= ' '){
var newsDiv = document .createElement(' div' );
newsDiv.setAttribute(' class',' news');
var person = document .createElement(' img');
newsDiv.innerText = text;
.trim(text); if(textTrim != ''){ var newsDiv = document.createElement('div'); newsDiv.setAttribute('class', 'news'); var person = document.createElement('img'); newsDiv.innerText = text;
这篇关于使用DOM和javascript创建html代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文