Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <!DOCTYPE html>
<html>
  <head>
    <meta charset="utf8">
    <title>sum price</title>
  </head>
  <body>
    <table>
      <thead>
        <tr>
          <th>商品</th>
          <th>価格</th>
          <th></th>
        </tr>
      </thead>
      <tbody>
        <tr>
          <td>デスクトップPC</td>
          <td class="price">200000</td>
          <td><input type="button" id="delete" value="削除"></td>
        </tr>
        <tr>
          <td>モニター</td>
          <td class="price">50000</td>
          <td><input type="button" id="delete" value="削除"></td>
        </tr>
        <tr>
          <td>キーボード</td>
          <td class="price">15000</td>
          <td><input type="button" id="delete" value="削除"></td>
        </tr>
        <tr>
          <td>マウス</td>
          <td class="price">6000</td>
          <td><input type="button" id="delete" value="削除"></td>
        </tr>
         <tr>
          <td>プリンター</td>
          <td class="price">40000</td>
          <td><input type="button" id="delete" value="削除"></td>
        </tr>
      </tbody>
    </table>
  </body>
  <div>
    <b><p class="sum_price">合計:0円</p></b>
  </div>
</html>
              
            
!

CSS

              
                body {
  background-color: #a3d5d3;
  font-family: 'Helvetica', 'Arial', sans-serif;
  width: 450px;
  margin: 0 auto;
  padding: 20px;
}

table, input {
 margin: 5px;
}

input[type=text] {
 width: 120px;
}

table,tr,th,td {
  font-size: 14px;
  width: 70%;
  list-style-type: none;
  border-radius: 3px;
  border: 1px solid #000;
  padding: 5px;
}

td {
  background: #eeeff0;
  padding-left: 12px;
}


              
            
!

JS

              
                $(function(){
  // 画面表示時に価格の合計値を計算
  sum();

  // 削除ボタン押下時の処理
  // ↓最初の削除ボタンしか反応しない23
  //$("#delete").click(function(event){
  // ↓すべての削除ボタンが反応する
  $("[id=delete]").click(function(event){
    var target = $(event.target);
    target.parents("tr").remove();
    // 合計値を再計算
    sum();
  });
  
  /**** 共通関数 ****/
  // 要素を削除する
  function deleteElement(name, element) {
    return;
  }

  // 合計値を求める
  function sum(){
    // 表の金額を取得する(tdの奇数列を取得)
    var pricelist = $("table td[class=price]").map(function(index, val){
      var price = parseInt($(val).text());
      if(price >= 0) {
        return price;
      } else {
        return null;
      }
    });
    // 価格の合計を求める
    var total = 0;
    pricelist.each(function(index, val){
      total = total + val;
    });
    $(".sum_price").text("合計:"+total+"円");
  }
});	
              
            
!
999px

Console