class ="Calculation"をクリックした際、クリックした要素の値をcookieに設定しようとしたがデベロッパーツールで確認したところname=SetCalculationのcookie情報が設定されないので原因をご教授ください。
index.html
<!DOCTYPE html> <html lang="ja"> <head> <meta charset="UTF-8"> <link rel="stylesheet" href="style.css"> <script src ="https://code.jquery.com/jquery-3.0.0.js"></script> <script src ="https://code.jquery.com/jquery-migrate-3.3.2.js"></script> <script src="https://code.jquery.com/jquery-3.3.1.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-cookie/1.4.1/jquery.cookie.js"></script> </head> <body> <table> <thead> <tr> <th id="title"> 電卓 </th> </tr> </thead> <tbody> <tr> <td >0</td> <td id="setnumber"></td> <td class="hidden-td"></td> <td id="clear">C</td> </tr> <tr> <td class="num" value="7">7</td> <td class="num" value="8">8</td> <td class="num" value="9">9</td> <td class="Calculation">÷</td> </tr> <tr> <td class="num" value="4">4</td> <td class="num" value="5">5</td> <td class="num" value="6">6</td> <td class="Calculation">×</td> </tr> <tr> <td class="num" value="1">1</td> <td class="num" value="2">2</td> <td class="num" value="3">3</td> <td class="Calculation">-</td> </tr> <tr> <td class="zero">0</td> <td>.</td> <td class="Calculation">+</td> <td>=</td> </tr> </tbody> </table> <script src="main.js"></script> </body> </html>
main.js
"use strict"; { var totalNum = ""; var setnum = document.getElementById('setnumber'); jQuery(function(){ for(var i=0;i<jQuery('.num').length;i++){ var num = 'selectnum'+(i+1); jQuery('.num').eq(i).addClass(num); } }); getNum(); getZero(); Calculation(); function openNum(setnum){ var SetNum = document.getElementById('setnumber'); if(setnum == 0){ if(totalNum == 0){ totalNum = setnum; }else{ totalNum = totalNum + setnum; } }else{ if(totalNum == 0){ totalNum = setnum; }else{ totalNum = totalNum + setnum; } } jQuery(SetNum).text(totalNum); } function getNum(){ jQuery('.num').click(function(){ var getnum = jQuery(this).text(); openNum(getnum); }); }; function getZero(){ jQuery('.zero').click(function(){ var getzero = jQuery(this).text(); openNum(getzero); }); }; function Calculation(){ jQuery('.Calculation').click(function(){ var calculation = jQuery(this).text(); setCookie(calculation); }); } function setCookie(setcookie){ jQuery.cookie('SetCalculation', setcookie); } }
回答1件
あなたの回答
tips
プレビュー