javascript - 单击按钮时重叠

标签 javascript html css

The sidebox

所以我在上面有一个边箱,它充当了账单。

HTML
    </div>
<div id="crt_user">
    <h1>Summary: (Choose items )</h1>
    <p>Amt left in Wallet: 1234<br>
     <span id="left">Bill Amt:</span> 
     <!--the container where the price is shown-->
     <div id="tags">
         <span id="rupee" style="font-family: DejaVu Sans;">&#x20b9;</span>
        <div id="result">0</div>
    </div>  

     <button id="clear">Clear</button>
    </p>     
    </div>

侧框具有以下 css:

  /*#crt_user header and ruppe symbol */
#left {
position:absolute;
top:85%;
left:0%;
font-size:1rem;
}
#rupee {
position:absolute;
top:-10%;
left:0%;
}
#result {
  position:absolute;
  top:2%;
  left:10%;
  /* background-color: red; */
  height:90%;
  width:60%;
}

因此,当单击下面的其中一个按钮时,上面的边栏会动态显示账单金额。

the buttons

按钮代码:

<button class="items" id="34">Pani Puri &emsp;  <span style="font-family: 
DejaVu Sans;">&#x20b9;</span>50</button> <br>

这背后的js是:

 function main() {
   var item=document.getElementsByClassName('items');
   var screen = document.getElementById("tags");
   var result = document.getElementById("result");
   var price=0;
    var prices =



[1,2,3,4,5,6,7,8,9,11,12,13,14,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42];

for(var i=0;i<item.length;i++) {
      item[i].addEventListener("click",function() {
           var e = parseInt(this.getAttribute('id'));
           console.log(prices[e]); 
            document.getElementById(this.getAttribute('id')).disabled =true;
            price += prices[e];
              screen.innerHTML = '<span id="rupee" style="font-family: 
          DejaVu Sans;">&#x20b9;</span>' +price;
     }); //end EventListener functionality
     }
 }

然而这发生了: The error

我该如何解决这个问题? boundry of the box(height width)

最佳答案

您应该在卢比符号后的 span 标签中使用  ,如下所示。

screen.innerHTML = '<span id="rupee" style="font-family: 
          DejaVu Sans;">&#x20b9;</span> &nbsp; &nbsp; ' +price;

或者将 price 变量包装在 span 标签中并给它们留边距'

screen.innerHTML = '<span id="rupee" style="font-family: 
          DejaVu Sans;">&#x20b9;</span> <span style="margin-left:10px;">' +price+'</span>';

关于javascript - 单击按钮时重叠,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47409874/

相关文章:

javascript - System.Windows.Controls.WebBrowser(IFramed窗口)如何与其xaml(WPF)中的父 View 通信

javascript - 使用 jQuery 显示/隐藏 Div

html - CSS3变换,想保持背景图片不旋转

css - 背景颜色在左侧和顶部的背景图像上产生

html - 使用 CSS 网格创建 3x3 响应式布局

javascript - 面板上的双击事件

javascript - 如何在服务器端禁用/忽略富链接预览

jquery - CSS 没有链接/显示?

javascript - 奇怪的分配 IDE 警告

javascript - 带有 jquery 的 HTML slider 显示第一张幻灯片的时间太长