데이터 목록에서 항목을 두 번 이상 추가 / 제거하는 데 문제가 있습니다.

알 모 그렌의 뇌

여러분 안녕하세요, 저는 사용자가 재료 목록을 추가 할 수 있도록 노력하고 있습니다. 그가 재료 이름을 입력하거나 제안 목록에서 선택할 수있는 텍스트 입력이 있습니다 (데이터 목록과 함께 입력을 사용했습니다). 추가 버튼을 클릭하면 항목이 목록에 추가되고 제안 목록 (데이터 목록)에서 제거됩니다. 목록에서 항목을 제거하면 재료 목록에서 제거되고 제안 목록으로 돌아갑니다. 일반적으로 다음과 같습니다. 재료 추가 코드는 잘 작동하지만 처음에만 작동합니다. 사용자가 재료 목록에서 항목을 제거하고 나중에 다시 추가 할 항목을 선택하면 제안 목록에서 제거되지 않습니다. "반환"기능에 문제가있는 것 같습니다 ..

다음은 코드 스 니펫입니다 ( "비닐 봉지"와 같은 항목을 재료에 추가 한 다음 제거한 다음 다시 추가하십시오).

function removeItem(list) { //removes item from suggestions list
  var item = $('input#' + list).val();
  if ($('option[value="' + item + '"]'))
    $('option[value="' + item + '"]').remove();
}


function returnItem(e) { //returns item to suggestions list
  var optionVal = $(e).closest("td").next().children("label").html();
  var newOption = new Option(optionVal);
  $("#suggests").append(newOption);
}


function addIngredient(e) { //adds item to ingredient list
  var inputContent = document.getElementById("addIngreField").value;
  if (inputContent != "") {
    var table = document.getElementById("ingredients");
    var row = table.insertRow(table.rows.length - 1);
    var cell1 = row.insertCell(0);
    cell1.style.textAlign = "left";
    cell1.innerHTML = "<input class='removeIngre' type='button' value='-' onclick='returnItem(this) ; removeIngredient(this)'>";
    var cell2 = row.insertCell(1);
    cell2.innerHTML = "<label class='ingred'>" + inputContent + "</label>";
    document.getElementById("addIngreField").value = "";
  }
};


function removeIngredient(e) { //removes item from ingredients list
  var row = e.parentNode.parentNode;
  row.parentNode.removeChild(row);
}
.ingred {
  display: block;
  position: relative;
  width: 200px;
  margin-bottom: 12px;
  font-size: 20px;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
  color: black;
  font-family: "Muli-Reg";
}

.addIngre {
  cursor: pointer;
  outline: none;
  height: 30px;
  width: 30px;
  border-radius: 50%;
  border: none;
  background-color: green;
  line-height: 5px;
  color: white;
  font-size: 18px;
  font-weight: bold;
  font-family: "Muli-Reg";
}

.removeIngre {
  cursor: pointer;
  outline: none;
  height: 30px;
  width: 30px;
  border-radius: 50%;
  border: none;
  background-color: #cc0000;
  line-height: 5px;
  color: white;
  font-size: 18px;
  font-weight: bold;
  font-family: "Muli-Reg";
}

.addSte {
  cursor: pointer;
  outline: none;
  height: 25px;
  width: 25px;
  border-radius: 50%;
  border: none;
  background-color: green;
  color: white;
  font-size: 18px;
  font-weight: bold
}

.removeSte {
  cursor: pointer;
  outline: none;
  opacity: 0.5;
  height: 25px;
  width: 25px;
  border-radius: 50%;
  border: none;
  background-color: #cc0000;
  color: white;
  font-size: 18px;
  font-weight: bold
}

.removeIngre:hover {
  opacity: 1;
}

.removeSte:hover {
  opacity: 1;
}

#add {
  cursor: pointer;
}

#stepsTable {
  counter-reset: row-num;
}

#stepsTable tr {
  counter-increment: row-num;
}

#stepsTable tr td:nth-child(2)::before {
  content: counter(row-num);
}

input:focus::-webkit-input-placeholder {
  color: transparent;
}

input:focus:-moz-placeholder {
  color: transparent;
}


/* FF 4-18 */

input:focus::-moz-placeholder {
  color: transparent;
}


/* FF 19+ */

input:focus:-ms-input-placeholder {
  color: transparent;
}


/* IE 10+ */

textarea:focus::-webkit-input-placeholder {
  color: transparent;
}

textarea:focus:-moz-placeholder {
  color: transparent;
}


/* FF 4-18 */

textarea:focus::-moz-placeholder {
  color: transparent;
}


/* FF 19+ */

textarea:focus:-ms-input-placeholder {
  color: transparent;
}


/* IE 10+ */
<link rel="stylesheet" type="text/css" href="CSS/Navigation-visitor.css">
<link rel="stylesheet" type="text/css" href="CSS/addArtwork.css">
<link rel="stylesheet" type="text/css" href="CSS/footer.css">
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<script src="JS/jquery-ui-1.12.1.custom/jquery-ui.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="JS/menuBar.js"></script>

<table id="ingredients" style="text-align: left; margin: auto; width:400px; font-family: " Muli-Reg ";">

  <tr>
    <td colspan="2">
      <p class="fieldTitle" style="color: gray; font-size: 22px;">Ingredients</p>
    </td>
  </tr>

  <tr id="addI">
    <td style="text-align: left; width: 50px;">
      <input class="addIngre" type="button" value="+" onclick="removeItem('addIngreField'); addIngredient()">
    </td>
    <td>
      <input id="addIngreField" type="text" maxlength="300" style="border: solid black; padding-left: 10px; padding-right: 10px; outline: none;  border-radius: 20px; font-size: 15px; height: 30px; width: 95%; text-align:left" list="suggests">

      <datalist id="suggests">
                <option value="Plastic Bags">
                <option value="colored paper">
                <option value="wood frames">
                <option value="Used Fabrics">
                <option value="Terapak Cartons">
                <option value="Hair ties">
                <option value="Newspaper">
                <option value="Cardboards">
                <option value="Pizza Box">
                <option value="Aluminum Foil">
                <option value="Cloth Hangers">
                <option value="CD's">
                <option value="Leather">
              </datalist>
    </td>
  </tr>


  <tr>
    <td colspan="2" style="text-align: right; height: 50px;">
      <button style="border: none; border-radius: 10px; height: 40px; width: 80px; color: dimgrey; font-size: 22px; background-color: darkgrey; " class="fieldTitle">next</button>
    </td>
  </tr>
  
</table>

SpiritOfDragon

옵션을 다시 생성 할 때 값 속성을 추가해야합니다. new Option(optionVal, optionVal)

function removeItem(list) { //removes item from suggestions list
  var item = $('input#' + list).val();
  if ($('option[value="' + item + '"]'))
    $('option[value="' + item + '"]').remove();
}


function returnItem(e) { //returns item to suggestions list
  var optionVal = $(e).closest("td").next().children("label").html();
  var newOption = new Option(optionVal, optionVal);
  $("#suggests").append(newOption);
}


function addIngredient(e) { //adds item to ingredient list
  var inputContent = document.getElementById("addIngreField").value;
  if (inputContent != "") {
    var table = document.getElementById("ingredients");
    var row = table.insertRow(table.rows.length - 1);
    var cell1 = row.insertCell(0);
    cell1.style.textAlign = "left";
    cell1.innerHTML = "<input class='removeIngre' type='button' value='-' onclick='returnItem(this) ; removeIngredient(this)'>";
    var cell2 = row.insertCell(1);
    cell2.innerHTML = "<label class='ingred'>" + inputContent + "</label>";
    document.getElementById("addIngreField").value = "";
  }
};


function removeIngredient(e) { //removes item from ingredients list
  var row = e.parentNode.parentNode;
  row.parentNode.removeChild(row);
}
.ingred {
  display: block;
  position: relative;
  width: 200px;
  margin-bottom: 12px;
  font-size: 20px;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
  color: black;
  font-family: "Muli-Reg";
}

.addIngre {
  cursor: pointer;
  outline: none;
  height: 30px;
  width: 30px;
  border-radius: 50%;
  border: none;
  background-color: green;
  line-height: 5px;
  color: white;
  font-size: 18px;
  font-weight: bold;
  font-family: "Muli-Reg";
}

.removeIngre {
  cursor: pointer;
  outline: none;
  height: 30px;
  width: 30px;
  border-radius: 50%;
  border: none;
  background-color: #cc0000;
  line-height: 5px;
  color: white;
  font-size: 18px;
  font-weight: bold;
  font-family: "Muli-Reg";
}

.addSte {
  cursor: pointer;
  outline: none;
  height: 25px;
  width: 25px;
  border-radius: 50%;
  border: none;
  background-color: green;
  color: white;
  font-size: 18px;
  font-weight: bold
}

.removeSte {
  cursor: pointer;
  outline: none;
  opacity: 0.5;
  height: 25px;
  width: 25px;
  border-radius: 50%;
  border: none;
  background-color: #cc0000;
  color: white;
  font-size: 18px;
  font-weight: bold
}

.removeIngre:hover {
  opacity: 1;
}

.removeSte:hover {
  opacity: 1;
}

#add {
  cursor: pointer;
}

#stepsTable {
  counter-reset: row-num;
}

#stepsTable tr {
  counter-increment: row-num;
}

#stepsTable tr td:nth-child(2)::before {
  content: counter(row-num);
}

input:focus::-webkit-input-placeholder {
  color: transparent;
}

input:focus:-moz-placeholder {
  color: transparent;
}


/* FF 4-18 */

input:focus::-moz-placeholder {
  color: transparent;
}


/* FF 19+ */

input:focus:-ms-input-placeholder {
  color: transparent;
}


/* IE 10+ */

textarea:focus::-webkit-input-placeholder {
  color: transparent;
}

textarea:focus:-moz-placeholder {
  color: transparent;
}


/* FF 4-18 */

textarea:focus::-moz-placeholder {
  color: transparent;
}


/* FF 19+ */

textarea:focus:-ms-input-placeholder {
  color: transparent;
}


/* IE 10+ */
<link rel="stylesheet" type="text/css" href="CSS/Navigation-visitor.css">
<link rel="stylesheet" type="text/css" href="CSS/addArtwork.css">
<link rel="stylesheet" type="text/css" href="CSS/footer.css">
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<script src="JS/jquery-ui-1.12.1.custom/jquery-ui.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="JS/menuBar.js"></script>

<table id="ingredients" style="text-align: left; margin: auto; width:400px; font-family: " Muli-Reg ";">

  <tr>
    <td colspan="2">
      <p class="fieldTitle" style="color: gray; font-size: 22px;">Ingredients</p>
    </td>
  </tr>

  <tr id="addI">
    <td style="text-align: left; width: 50px;">
      <input class="addIngre" type="button" value="+" onclick="removeItem('addIngreField'); addIngredient()">
    </td>
    <td>
      <input id="addIngreField" type="text" maxlength="300" style="border: solid black; padding-left: 10px; padding-right: 10px; outline: none;  border-radius: 20px; font-size: 15px; height: 30px; width: 95%; text-align:left" list="suggests">

      <datalist id="suggests">
                <option value="Plastic Bags">
                <option value="colored paper">
                <option value="wood frames">
                <option value="Used Fabrics">
                <option value="Terapak Cartons">
                <option value="Hair ties">
                <option value="Newspaper">
                <option value="Cardboards">
                <option value="Pizza Box">
                <option value="Aluminum Foil">
                <option value="Cloth Hangers">
                <option value="CD's">
                <option value="Leather">
              </datalist>
    </td>
  </tr>


  <tr>
    <td colspan="2" style="text-align: right; height: 50px;">
      <button style="border: none; border-radius: 10px; height: 40px; width: 80px; color: dimgrey; font-size: 22px; background-color: darkgrey; " class="fieldTitle">next</button>
    </td>
  </tr>
  
</table>

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

셀레늄을 사용하여 두 가지 깊이에서 항목을 긁는 데 문제가 있습니다.

분류에서Dev

목록에서 항목을 제거하는 데 어려움이 있습니다.

분류에서Dev

jQuery로 목록에서 항목을 추가하고 제거하는 데 도움이 필요합니다.

분류에서Dev

내 Python 프로그램 목록에서 중복 항목을 제거하는 데 문제가 있습니다.

분류에서Dev

동일한 페이지에서이 기능을 두 번 사용하는 데 문제가 있습니다.

분류에서Dev

데이터 테이블을 사용하여 v-for 목록에서 항목 추가 또는 제거

분류에서Dev

ObservableCollection에서 항목을 제거하는 데 문제가 있습니다. 뭔가 잘못하고 있습니다.

분류에서Dev

immutable.js가있는 React, Redux : 목록에서 하나의 항목을 삭제할 때 올바른 상태 데이터를 가져올 수 없습니다.

분류에서Dev

첫 번째 열의 두 데이터 프레임에서 동일한 항목을 비교하고 다음 열로 이동 / 추가 및 차이점 추가

분류에서Dev

List <string>에 추가하지만 항목이 추가되는 데 문제가 있습니다.

분류에서Dev

C ++에서 두 항목 간의 차이를 찾는 데 문제가 있습니다.

분류에서Dev

할 일 목록 프로젝트에서 항목을 삭제하는 데 문제가 있습니다.

분류에서Dev

itertools와 zip을 함께 사용하여 길이가 다른 두 목록에서 사전을 만드는 데 문제가 있습니다.

분류에서Dev

녹아웃 : 새로 추가 된 항목을 제거하는 데 문제가 있습니다.

분류에서Dev

observableArray에서 선택한 목록 항목을 다른 observableArray로 푸시하는 데 문제가 있습니까? 바이올린 제공

분류에서Dev

한 목록 상자에서 다른 목록 상자로 항목을 이동할 때 두 번째 목록 상자로 이동하는 문자열에 어떻게 추가합니까?

분류에서Dev

요소에 이벤트를 두 번 추가하는 데 문제가 있습니까?

분류에서Dev

데이터베이스에 추가하는 데 문제가 있습니다.

분류에서Dev

파이썬에서 목록 목록을 만드는 데 문제가 있습니다.

분류에서Dev

두 개의 개별 소스 목록에있는 데이터에서 새 목록을 만들 때-소스 데이터를 올바르게 추가하는 데 어려움이 있습니다. (파이썬)

분류에서Dev

github repo에서 이상한 이름의 파일을 제거하는 데 문제가 있습니다.

분류에서Dev

목록 개체에 새 값을 추가하는 데 문제가 있습니다.

분류에서Dev

데이터 프레임을 추가하는 데 문제가 있습니다.

분류에서Dev

파이 게임에서 새 항목을 표시하는 데 문제가 있습니다.

분류에서Dev

WPF ListView에 항목을 추가하는 데 문제가 있음

분류에서Dev

Selenium을 사용하여 웹 페이지에서 데이터를 추출하는 데 문제가 있습니다.

분류에서Dev

제목, 설명이 포함 된 두 번째 양식의 사용자 입력을 데이터 배열에 추가하려고하지만 할 수 없습니다.

분류에서Dev

반응에서 useState로 주문에 항목을 추가하는 데 문제가 있습니다.

분류에서Dev

루프에서 데이터를 추출하는 데 문제가 있습니다.

Related 관련 기사

  1. 1

    셀레늄을 사용하여 두 가지 깊이에서 항목을 긁는 데 문제가 있습니다.

  2. 2

    목록에서 항목을 제거하는 데 어려움이 있습니다.

  3. 3

    jQuery로 목록에서 항목을 추가하고 제거하는 데 도움이 필요합니다.

  4. 4

    내 Python 프로그램 목록에서 중복 항목을 제거하는 데 문제가 있습니다.

  5. 5

    동일한 페이지에서이 기능을 두 번 사용하는 데 문제가 있습니다.

  6. 6

    데이터 테이블을 사용하여 v-for 목록에서 항목 추가 또는 제거

  7. 7

    ObservableCollection에서 항목을 제거하는 데 문제가 있습니다. 뭔가 잘못하고 있습니다.

  8. 8

    immutable.js가있는 React, Redux : 목록에서 하나의 항목을 삭제할 때 올바른 상태 데이터를 가져올 수 없습니다.

  9. 9

    첫 번째 열의 두 데이터 프레임에서 동일한 항목을 비교하고 다음 열로 이동 / 추가 및 차이점 추가

  10. 10

    List <string>에 추가하지만 항목이 추가되는 데 문제가 있습니다.

  11. 11

    C ++에서 두 항목 간의 차이를 찾는 데 문제가 있습니다.

  12. 12

    할 일 목록 프로젝트에서 항목을 삭제하는 데 문제가 있습니다.

  13. 13

    itertools와 zip을 함께 사용하여 길이가 다른 두 목록에서 사전을 만드는 데 문제가 있습니다.

  14. 14

    녹아웃 : 새로 추가 된 항목을 제거하는 데 문제가 있습니다.

  15. 15

    observableArray에서 선택한 목록 항목을 다른 observableArray로 푸시하는 데 문제가 있습니까? 바이올린 제공

  16. 16

    한 목록 상자에서 다른 목록 상자로 항목을 이동할 때 두 번째 목록 상자로 이동하는 문자열에 어떻게 추가합니까?

  17. 17

    요소에 이벤트를 두 번 추가하는 데 문제가 있습니까?

  18. 18

    데이터베이스에 추가하는 데 문제가 있습니다.

  19. 19

    파이썬에서 목록 목록을 만드는 데 문제가 있습니다.

  20. 20

    두 개의 개별 소스 목록에있는 데이터에서 새 목록을 만들 때-소스 데이터를 올바르게 추가하는 데 어려움이 있습니다. (파이썬)

  21. 21

    github repo에서 이상한 이름의 파일을 제거하는 데 문제가 있습니다.

  22. 22

    목록 개체에 새 값을 추가하는 데 문제가 있습니다.

  23. 23

    데이터 프레임을 추가하는 데 문제가 있습니다.

  24. 24

    파이 게임에서 새 항목을 표시하는 데 문제가 있습니다.

  25. 25

    WPF ListView에 항목을 추가하는 데 문제가 있음

  26. 26

    Selenium을 사용하여 웹 페이지에서 데이터를 추출하는 데 문제가 있습니다.

  27. 27

    제목, 설명이 포함 된 두 번째 양식의 사용자 입력을 데이터 배열에 추가하려고하지만 할 수 없습니다.

  28. 28

    반응에서 useState로 주문에 항목을 추가하는 데 문제가 있습니다.

  29. 29

    루프에서 데이터를 추출하는 데 문제가 있습니다.

뜨겁다태그

보관