首页 > 解决方案 > 如何在javascript中的同一行中获取锚点和段落?

问题描述

我试图用 LeafletJs 创建一个项目,这包括制作一个显示所有商店位置的面板,如下所示: 在此处输入图像描述

但是,我希望商店的名称“pizza outlet x”位于地址之前的单独一行。这是代码

const tileUrl = 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png';
const attribution =
        '&copy; <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();

我该怎么做呢?

标签: javascriptleaflet

解决方案


你不能只添加一个 br 标签吗?使用您的方法:

常量 br = document.createElement('br');

div.appendChild(br); //放置在锚点之后


推荐阅读