Javascript 如何使用JS创建并行引导列?
我想使用JavaScript动态创建并行列,但我不知道如何创建它们。这是我想用JS创建的HTML代码Javascript 如何使用JS创建并行引导列?,javascript,html,twitter-bootstrap,Javascript,Html,Twitter Bootstrap,我想使用JavaScript动态创建并行列,但我不知道如何创建它们。这是我想用JS创建的HTML代码 <div class="container"> <div class="row"> <div class="col"> <textarea rows="20" cols="50">At w3schools.com you will learn how to make a website. We offer free tuto
<div class="container">
<div class="row">
<div class="col">
<textarea rows="20" cols="50">At w3schools.com you will learn how to make a website. We offer free tutorials in all web development technologies.</textarea>
</div>
<div class="col">
<p>Que</p>
<div class="form-group">
<div class="input-group">
<input class="form-control" placeholder="test" />
</div>
</div>
</div>
</div>
</div>
在w3schools.com,您将学习如何创建网站。我们提供所有web开发技术的免费教程。
阙
使用cloneNode
,然后将child
附加到容器中
伪代码:
var row=document.getElementByClassName(“row”)[0];
var container=document.getElementById(“容器”)[0];
var clone=row.cloneNode(true);
container.appendChild(克隆)代码>使用cloneNode
,然后appendChild
到容器中
伪代码:
var row=document.getElementByClassName(“row”)[0];
var container=document.getElementById(“容器”)[0];
var clone=row.cloneNode(true);
container.appendChild(克隆)代码>这将让您了解如何在引导网格中动态生成
HTML:
JS:
let leftColumn=`在w3schools.com上,您将学习如何创建网站。我们提供所有web开发技术的免费教程`
设右列=`
阙
`;
document.getElementById(“内容”).innerHTML=`
${leftColumn}
${rightColumn}
`;
这将让您了解如何在引导网格中动态生成
HTML:
JS:
let leftColumn=`在w3schools.com上,您将学习如何创建网站。我们提供所有web开发技术的免费教程`
设右列=`
阙
`;
document.getElementById(“内容”).innerHTML=`
${leftColumn}
${rightColumn}
`;
使用JS,使其动态化并不容易,因为您不能只将字符串(也包括模板文本)附加到节点。您必须首先创建一个节点,然后添加一个内容,然后追加和全部
不过,jQuery非常简单:
const appendChild = (content) => {
$('.row').append(`
<div class="col">${content}</div>
`)
}
// don't know where these would come from, maybe you're getting this info form somewhere outside?
const colOne = `<textarea rows="20" cols="50">
At w3schools.com you will learn how to make a website. We offer free tutorials in all web development technologies.
</textarea>
`;
const colTwo =`<p>Que</p>
<div class="form-group">
<div class="input-group">
<input class="form-control" placeholder="test" />
</div>
</div>
`;
// wherever you're getting the ones from above, you could call this function directly there
appendChild(colOne);
appendChild(colTwo);
const appendChild=(content)=>{
$('.row')。追加(`
${content}
`)
}
//不知道这些是从哪里来的,也许你在外面的某个地方得到了这张信息表?
常数冒号=`
在w3schools.com,您将学习如何创建网站。我们提供所有web开发技术的免费教程。
`;
常数colTwo=`Que
`;
//无论从哪里获取上面的函数,都可以直接在那里调用此函数
儿童(科隆);
儿童(colTwo);
---------------------------编辑---------------------------
如评论中所述,可以在VanillaJS中执行此操作,因此以下是JS选项:
const row = document.querySelector('.row')
const appendChild = (content) => {
row.insertAdjacentHTML('beforeend', `
<div class="col">${content}</div>
`)
}
// don't know where these would come from, maybe you're getting this info form somewhere outside?
const colOne =
`<textarea rows="20" cols="50">
At w3schools.com you will learn how to make a website. We offer free tutorials in all web development technologies.
</textarea>
`;
const colTwo =
`<p>Que</p>
<div class="form-group">
<div class="input-group">
<input class="form-control" placeholder="test" />
</div>
</div>
`;
// wherever you're getting the ones from above, you could call this function directly there
appendChild(colOne);
appendChild(colTwo);
const row=document.querySelector(“.row”)
const appendChild=(内容)=>{
row.insertAdjacentHTML('beforeend'`
${content}
`)
}
//不知道这些是从哪里来的,也许你在外面的某个地方得到了这张信息表?
常数冒号=
`
在w3schools.com,您将学习如何创建网站。我们提供所有web开发技术的免费教程。
`;
康斯特科尔杜=
` 阙
`;
//无论从哪里获取上面的函数,都可以直接在那里调用此函数
儿童(科隆);
儿童(colTwo);
这是JS的,要使其动态化并不容易,因为您不能只将字符串(也就是模板文本)附加到节点。您必须首先创建一个节点,然后添加一个内容,然后追加和全部
不过,jQuery非常简单:
const appendChild = (content) => {
$('.row').append(`
<div class="col">${content}</div>
`)
}
// don't know where these would come from, maybe you're getting this info form somewhere outside?
const colOne = `<textarea rows="20" cols="50">
At w3schools.com you will learn how to make a website. We offer free tutorials in all web development technologies.
</textarea>
`;
const colTwo =`<p>Que</p>
<div class="form-group">
<div class="input-group">
<input class="form-control" placeholder="test" />
</div>
</div>
`;
// wherever you're getting the ones from above, you could call this function directly there
appendChild(colOne);
appendChild(colTwo);
const appendChild=(content)=>{
$('.row')。追加(`
${content}
`)
}
//不知道这些是从哪里来的,也许你在外面的某个地方得到了这张信息表?
常数冒号=`
在w3schools.com,您将学习如何创建网站。我们提供所有web开发技术的免费教程。
`;
常数colTwo=`Que
`;
//无论从哪里获取上面的函数,都可以直接在那里调用此函数
儿童(科隆);
儿童(colTwo);
---------------------------编辑---------------------------
如评论中所述,可以在VanillaJS中执行此操作,因此以下是JS选项:
const row = document.querySelector('.row')
const appendChild = (content) => {
row.insertAdjacentHTML('beforeend', `
<div class="col">${content}</div>
`)
}
// don't know where these would come from, maybe you're getting this info form somewhere outside?
const colOne =
`<textarea rows="20" cols="50">
At w3schools.com you will learn how to make a website. We offer free tutorials in all web development technologies.
</textarea>
`;
const colTwo =
`<p>Que</p>
<div class="form-group">
<div class="input-group">
<input class="form-control" placeholder="test" />
</div>
</div>
`;
// wherever you're getting the ones from above, you could call this function directly there
appendChild(colOne);
appendChild(colTwo);
const row=document.querySelector(“.row”)
const appendChild=(内容)=>{
row.insertAdjacentHTML('beforeend'`
${content}
`)
}
//不知道这些是从哪里来的,也许你在外面的某个地方得到了这张信息表?
常数冒号=
`
在w3schools.com,您将学习如何创建网站。我们提供所有web开发技术的免费教程。
`;
康斯特科尔杜=
` 阙
`;
//无论从哪里获取上面的函数,都可以直接在那里调用此函数
儿童(科隆);
儿童(colTwo);
以下是您想要实现的目标?一般来说,Bootstrap的网格用于这些目的。您想要实现什么?通常,引导程序的网格用于此类目的。实际上,您可以将字符串附加到HTML中的现有元素,即使没有附加到innerHTML
的缺点。方法被调用。(或为文本节点插入邻接文本。)实际上,您可以将字符串附加到HTML中的现有元素,即使没有附加到innerHTML
的缺点。方法被调用。(或为文本节点插入相邻文本。)