ZBLOG

for (const item of jsonRes) { if (item.code === 'customerInfo') {} //客户信息展示 if (item.code === 'loan') { // 合同展示 const buttonContainer = document.createElement('div'); buttonContainer.innerHTM...

要找到 keyInfo 元素并在添加按钮的部分进行 CSS 样式的修改,可以按照以下方式进行整合。在你的代码中,我们可以通过获取 keyInfo 的元素,然后在创建按钮后对其样式进行更改。下面是完整的代码示例:

for (const item of jsonRes) {
    if (item.code === 'customerInfo') {
        // 在这里处理客户信息展示
        const keyInfoElement = document.getElementById('idkeyInfo');
        
        // 修改 keyInfo 的样式
        if (keyInfoElement) {
            keyInfoElement.style.backgroundColor = 'lightblue';
            keyInfoElement.style.color = 'black';
            keyInfoElement.style.fontSize = '20px';
        }
    }

    if (item.code === 'loan') { // 合同展示
        const buttonContainer = document.createElement('div');
        buttonContainer.innerHTML = `
            <div class="button-container">
                <button class="btn" data-action="action1">按钮1</button>
                <button class="btn" data-action="action2">按钮2</button>
                <button class="btn" data-action="action3">按钮3</button>
                <button class="btn" data-action="action4">按钮4</button>
            </div>
        `;
        
        document.body.appendChild(buttonContainer);

        // 定位 buttonContainer 的位置
        buttonContainer.style.position = 'absolute';  // 或者使用其他定位方式,比如 relative, fixed等
        buttonContainer.style.top = '100px';          // 根据需要设置 Y 轴位置
        buttonContainer.style.left = '50px';          // 根据需要设置 X 轴位置

        buttonContainer.querySelectorAll('.btn').forEach(button => {
            button.addEventListener('click', function() {
                const action = this.getAttribute('data-action');
                switch (action) {
                    case 'action1':
                        console.log('按钮1被点击');
                        break;
                    case 'action2':
                        console.log('按钮2被点击');
                        break;
                    case 'action3':
                        console.log('按钮3被点击');
                        break;
                    case 'action4':
                        console.log('按钮4被点击');
                        break;
                    default:
                        break;
                }
            });
        });
    }
}

解释:

  1. 修改 keyInfo 的样式:在处理 'customerInfo' 时,我们通过 document.getElementById('idkeyInfo') 获取到该元素,并直接修改其 CSS 属性。

  2. 创建并定位新的按钮容器:我们在 'loan' 条件下创建一个新的 div 容器,里面包含多个按钮。然后我们给这个容器设置了绝对定位(也可以根据需求选择其他定位方式),并设定了它的位置。

请根据实际情况调整 topleft 值,以确保新添加的按钮容器能够出现在你希望的位置。


内容由零声教学AI助手提供,问题来源于学员提问

本站部分文章来源于网络,版权归原作者所有,如有侵权请联系站长删除。
转载请注明出处:https://golang.0voice.com/?id=22036

分享:
扫描分享到社交APP
上一篇
下一篇
发表列表
游客 游客
此处应有掌声~
评论列表

还没有评论,快来说点什么吧~

联系我们

在线咨询: 点击这里给我发消息

微信号:3007537140

上班时间: 10:30-22:30

关注我们
x

注册

已经有帐号?