test_result.ejs 1.72 KB
<!DOCTYPE html>
<html>

<head>
  <title>추천 카트</title>
  <link rel="stylesheet" type="text/css" href="test_result.css" />
</head>
<script>
  var item = '<%- body %>';
  var url = '<%- url %>';
  var stritem = item.split(".");
  function load() {
    return fetch("metadata/kart.json")
      .then((response) => response.json())
      .then((json) => json.kart);
  }
  load().then((kart) => {
    const div_target = document.querySelector("#total");
    var obj = document.createElement('text');
    var obj2 = document.createElement('text');
    for (var i = 0; i < kart.length; i++) {
      if (kart[i]['id'] == stritem[0]) {
        obj.id = "text1";
        obj2.id = "text2";
        obj.innerText = "나에게 맞는 카트는 ";
        obj2.innerText = kart[i]['name'];
        break;
      }
    }
    div_target.append(obj);
    div_target.append(obj2);
  });

  function Img() {
    return url + item;
  }
</script>

<body>
  <div id="total">
    <div id="words">
      <img id="imgkey" src="metadata/image/keyword.png">
    </div>
    <div id="rkart">
      <img id="imgId" src="">
      <script>document.getElementById("imgId").src = Img()</script>
    </div>
    <button id="reset" onClick="location.href='/test'">다시하기</button>
    <button id="home" onClick="location.href='/'">HOME</button>
  </div>
</body>
<script>
  var keyword = "<%- keyword %>";
  var keyarr = keyword.split(',');
  const div_target = document.querySelector("#words");
  var i = 0, index = 0;
  while (index < 7) {
    if (keyarr[index] != "empty") {
      var obj = document.createElement('button');
      obj.id = "word" + (i + 1);
      obj.innerText = '#' + keyarr[index];
      div_target.append(obj);
      i++;
    }
    index++;
  }
</script>

</html>