提问者:小点点

如何自定义我的HTML,如果它是在一个JS


下面是我的

profileContainer.innerHTML = 
`
<div class="col-md-12">
    <section class="jumbotron my-5">

        <h3 class="text-center">First Name: ${data.firstName}</h3>
        <h3 class="text-center">Last Name: ${data.lastName}</h3>
        <h3 class="text-center">Email: ${data.email}</h3>
        <h3 class="text-center">Contact Number: ${data.mobileNo}</h3>
        <h3 class="mt-5">Class History</h3>
        <table class="table">
            <thead>
                <tr>
                    <th> Course Name </th>
                    <th> Enrolled On </th>
                    <th> Status </th>
                </tr>
            </thead>
            <tbody id="coursesContainer"></tbody>
            </table> 
        </section>
    </div>
`

这是我的

<main class="container my-5">
    <div id="profileContainer" class="row">
        <div class="col-md-12">
            <section class="jumbotron text-center my-5">        
                <h2 class="my-5"><span class="spinner-border text-primary"></span> Fetching User 
               Details...</h2>
            </section>
        </div>
    </div>
    <!-- end row -->
</main>

这是预期的输出:profile

我尝试将配置文件的背景色从灰色更改为其他颜色,但是通过定位只会更改外部边框的颜色…请帮帮忙


共3个答案

匿名用户

您可以像对待任何其他HTML一样,以JS中指定的类或ID为目标。根据您尝试设置样式的页面上的特定元素,您可以尝试以为目标

如果没有看到CSS已经存在的内容来了解样式化目前应用于哪些元素(例如,灰色背景和边框半径实际绑定到哪个类),就很难提供细节。

匿名用户

基本上我们所做的就是为元素提供一个id或类。尝试这样做,然后在样式表中编码css。这是一个简单和最重要的方法,以摆脱这个摆脱。

匿名用户

您可以通过给它一个id来选择要更改的html元素,并通过使用javascript属性(getelementbyid)进行选择,然后通过使用innerhtml属性来更改其内部html

相关问题