javascript - 如何在javascript中的同一行中获取锚点和段落?
问题描述
我试图用 LeafletJs 创建一个项目,这包括制作一个显示所有商店位置的面板,如下所示:
但是,我希望商店的名称“pizza outlet x”位于地址之前的单独一行。这是代码
const tileUrl = 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png';
const attribution =
'© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors, Coded by coder\'s gyan with ❤️';
const tileLayer = L.tileLayer(tileUrl, { attribution });
tileLayer.addTo(myMap);
function makeList() {
const ul = document.querySelector('.list');
storeList.forEach((shop) => {
const li = document.createElement('li');
const div = document.createElement('div');
const anchor = document.createElement('a');
const para = document.createElement('para');
div.classList.add('shop-item');
anchor.innerText = shop.properties.name;
anchor.href = '#';
para.innerText = shop.properties.address;
div.appendChild(anchor);
div.appendChild(para);
li.appendChild(div);
ul.appendChild(li);
});
}
makeList();
我该怎么做呢?
解决方案
你不能只添加一个 br 标签吗?使用您的方法:
常量 br = document.createElement('br');
div.appendChild(br); //放置在锚点之后
推荐阅读
- google-chrome - Receiving ERR_CONNECTION_CLOSED when trying to connect to my Heroku App using Chrome
- html - How do i apply setting on a div?
- python - Changing the size of bootstrap cards in a Django project?
- node.js - Trouble running two Node.js api on a single droplet with PM2
- python - Reformatting Python Multiline Comments and Docstrings in PyCharm
- python - i can't run a linear regression and cross validation. can someone enlighten me? i get errors such as could not convert string to float
- r - mean() does not work after slice() in summarise() in a grouped data in R
- java - 在 Android 应用程序中,如何使用透明文本制作线性视图,以便父视图可见?
- push-notification - 如何在 OpenFire 中配置 FCM 推送通知
- java - Logback Appender 的静态上下文配置