ZBLOG

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

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

  1. for (const item of jsonRes) {
  2. if (item.code === 'customerInfo') {
  3. // 在这里处理客户信息展示
  4. const keyInfoElement = document.getElementById('idkeyInfo');
  5. // 修改 keyInfo 的样式
  6. if (keyInfoElement) {
  7. keyInfoElement.style.backgroundColor = 'lightblue';
  8. keyInfoElement.style.color = 'black';
  9. keyInfoElement.style.fontSize = '20px';
  10. }
  11. }
  12. if (item.code === 'loan') { // 合同展示
  13. const buttonContainer = document.createElement('div');
  14. buttonContainer.innerHTML = `
  15. <div class="button-container">
  16. <button class="btn" data-action="action1">按钮1</button>
  17. <button class="btn" data-action="action2">按钮2</button>
  18. <button class="btn" data-action="action3">按钮3</button>
  19. <button class="btn" data-action="action4">按钮4</button>
  20. </div>
  21. `;
  22. document.body.appendChild(buttonContainer);
  23. // 定位 buttonContainer 的位置
  24. buttonContainer.style.position = 'absolute'; // 或者使用其他定位方式,比如 relative, fixed等
  25. buttonContainer.style.top = '100px'; // 根据需要设置 Y 轴位置
  26. buttonContainer.style.left = '50px'; // 根据需要设置 X 轴位置
  27. buttonContainer.querySelectorAll('.btn').forEach(button => {
  28. button.addEventListener('click', function() {
  29. const action = this.getAttribute('data-action');
  30. switch (action) {
  31. case 'action1':
  32. console.log('按钮1被点击');
  33. break;
  34. case 'action2':
  35. console.log('按钮2被点击');
  36. break;
  37. case 'action3':
  38. console.log('按钮3被点击');
  39. break;
  40. case 'action4':
  41. console.log('按钮4被点击');
  42. break;
  43. default:
  44. break;
  45. }
  46. });
  47. });
  48. }
  49. }

解释:

  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

注册

已经有帐号?