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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ 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

              
                #buylist
  h1 Mybuylist 購物清單
  .buy_item.control_panel
    label 產品名
    input#input_name(placeholder="Ipadpro")
    label 價錢
    input#input_price(placeholder="34560")
    span.addbtn +新增
  #items_list
    //- li.buy_item 1.吹風機
    //-   .price 100
    //-   .del_btn X
    //- li.buy_item 2.吹風機
    //-   .price 100
    //-   .del_btn X
    //- li.buy_item 3.吹風機
    //-   .price 100
    //-   .del_btn X
    //- li.buy_item.total 總價
    //-   .price 500

              
            
!

CSS

              
                $color_black: #444
$color_yellow: #FFC954
$color_red: #FF3D4A
$color_white: #f3f3f3



*
  // border: solid 1px
  position: relative
  font-family:  'Roboto', sans-serif,"微軟正黑體"

html,body
  width: 100%
  height: 100%
  margin: 0
  display: flex
  justify-content: center
  align-items: center
  background-color: $color_yellow 
  
#buylist
  display: inline-block
  padding: 20px
  border: solid 4px $color_black
  background-color: $color_white 
  box-shadow: 0px 0px  20px rgba(0,0,0,0.3)
  // position: absolute
  // left: 50%
  // top: 50%
  // transform: translateX(-50%) translateY(-50%)
h1
  padding: 20px
  margin-top: -20px
  margin-left: -20px
  margin-right: -20px
  border-bottom: solid 4px $color_black
  background-color: $color_red
  color: $color_white
  font-weight: 300
  // box-sizing: border-box
  
#item_list
  margin-top: 10px
  padding: 5px
  
.buy_item
  padding: 5px
  list-style: none
  border: solid 3px black
  margin-top: 10px
  font-weight: 900

  & input
    width: 100px
    border: solid 3px
    padding: 2px
    
  & .price
     display: inline-block
     position: absolute
     padding-right: 8px
     padding-left: 8px
     right: 50px
     background-color: $color_yellow
     &:before   
       content: "$ "
      
  
  & .del_btn
    display: inline-block
    position: absolute
    padding: 0px 6px
    right: 10px
    cursor: pointer
    
    &:hover
      background-color: $color_red
      color: white
    
  & .addbtn
     cursor: pointer
     margin-left: 10px
     padding: 5px
     border: solid 3px $color_black
    
     &:hover
      background-color: $color_red
      color: white
    
.control_panel
    padding: 20px 
.total
  background-color: $color_red
  color: $color_white
  & .price
     background-color: transparent
  
    
    
    
              
            
!

JS

              
                var itemurl="https://awiclass.monoame.com/api/command.php?type=get&name=itemdata";




var shoplist={};
shoplist.name="Mybuylist 購物清單";
shoplist.time="2021/08/21";
shoplist.list=[
  {name: "吹風機",price:300},
  {name: "麥克風",price:9000},
  {name: "筆記型電腦",price:34000},
  {name: "Iphone 12",price:30000},
  {name: "神奇海螺",price:9999},
];

$.ajax({
  url: itemurl,
  success: function(res){
    shoplist.list=JSON.parse(res)
    showlist();
  }
  
  
});


var item_html="<li  id={{id}} class='buy_item'>{{num}}.{{item}}<div  class='price'>{{price}}</div><div id={{del_id}} data_del_id='{{delid}}' class='del_btn'>X</d></li>";

var total_html=" <li class='buy_item total'>總價<div class='price'>{{price}}</div>";


function showlist(){
   $("#items_list").html("");
  var total_price=0;
  for (var i=0;i<shoplist.list.length;i++){
    var item=shoplist.list[i];
    var item_id="buyitem_"+i;
    var del_item_id="del_buyitem_"+i;
    total_price+=parseInt(item.price);
    var current_item_html=
      item_html.replace("{{num}}",i+1)
               .replace("{{item}}",item.name)
               .replace("{{id}}",item_id)
               .replace("{{del_id}}",del_item_id)
               .replace("{{price}}",item.price)
               .replace("{{delid}}",i)
    ;
    $("#items_list").append(current_item_html);
    $("#"+del_item_id).click(
      function(){
        remove_item($(this).attr("data_del_id"));
      }
    );
  }
  var current_total_html=
      total_html.replace("{{price}}",total_price);
   $("#items_list").append(current_total_html);
  
}
showlist();

$(".addbtn").click(
  function(){
    shoplist.list.push(
  {
    name:$("#input_name").val(),
    price:$("#input_price").val()
   }
  );
  $("#input_name").val("");
  $("#input_price").val("");
  showlist();
 }
);


function remove_item(id){
  shoplist.list.splice(id,1);
  showlist();
}




              
            
!
999px

Console