2016-11-21 3 views
0

아래 코드에 문제가 있습니다. 두 번째 버튼은 작동하지 않는 것을 보여줍니다. 아무것도 열리지 않습니다. 문제는 Show ... if class로 변경했는데 둘 다 작동하지 않습니다. 그리고 각 행의 텍스트를 원하는 모든 여백없이 남아있을 수 있습니다,하지만 난 버튼 속성 ID의jquery html의 여러 버튼

<!DOCTYPE html> 
<html> 

    <body> 
    <!doctype html> 
    <html lang="en"> 

    <head> 
     <meta charset="utf-8"> 
     <meta name="viewport" content="width=device-width, initial-scale=1"> 
     <title>Cafeteria Orders Management System</title> 
     <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css"> 
     <link rel="stylesheet" href="/resources/demos/style.css"> 
     <style> 
     label, 
     input { 
      display: block; 
     } 

     input.text { 
      margin-bottom: 12px; 
      width: 95%; 
      padding: .4em; 
     } 

     fieldset { 
      padding: 0; 
      border: 0; 
      margin-top: 25px; 
     } 

     td { 
      max-width: 120px; 
      white-space: nowrap; 
     } 

     h1 { 
      font-size: 1.2em; 
      margin: .6em 0; 
     } 

     div#users-contain { 
      width: 300px; 
      margin: 20px 0; 
     } 

     div#users-contain table { 
      margin: 1em 0; 
      border-collapse: collapse; 
      width: 100%; 
     } 

     div#users-contain table td, 
     div#users-contain table th { 
      border: 9px solid #eee; 
      padding: .6em 120px; 
      text-align: left; 
     } 

     .ui-dialog .ui-state-error { 
      padding: .3em; 
     } 

     .validateTips { 
      border: 1px solid transparent; 
      padding: 0.3em; 
     } 

     </style> 
     <script src="https://code.jquery.com/jquery-1.12.4.js"></script> 
     <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script> 
     <script> 
     $(function() { 
      var dialog, form, 

      // From http://www.whatwg.org/specs/web-apps/current-work/multipage/states-of-the-type-attribute.html#e-mail-state-%28type=email%29 
      emailRegex = /^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-][email protected][a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/, 
      name = $("#name"), 
      email = $("#email"), 
      password = $("#password"), 
      allFields = $([]).add(name).add(email).add(password), 
      tips = $(".validateTips"); 

      function updateTips(t) { 
      tips 
       .text(t) 
       .addClass("ui-state-highlight"); 
      setTimeout(function() { 
       tips.removeClass("ui-state-highlight", 1500); 
      }, 500); 
      } 

      function checkLength(o, n, min, max) { 
      if (o.val().length > max || o.val().length < min) { 
       o.addClass("ui-state-error"); 
       updateTips("Length of " + n + " must be between " + 
       min + " and " + max + "."); 
       return false; 
      } else { 
       return true; 
      } 
      } 

      function checkRegexp(o, regexp, n) { 
      if (!(regexp.test(o.val()))) { 
       o.addClass("ui-state-error"); 
       updateTips(n); 
       return false; 
      } else { 
       return true; 
      } 
      } 

      function addUser() { 
      var valid = true; 
      allFields.removeClass("ui-state-error"); 

      valid = valid && checkLength(name, "username", 3, 16); 
      valid = valid && checkLength(email, "email", 6, 80); 
      valid = valid && checkLength(password, "password", 5, 16); 

      valid = valid && checkRegexp(name, /^[a-z]([0-9a-z_\s])+$/i, "Username may consist of a-z, 0-9, underscores, spaces and must begin with a letter."); 
      valid = valid && checkRegexp(email, emailRegex, "eg. [email protected]"); 
      valid = valid && checkRegexp(password, /^([0-9a-zA-Z])+$/, "Password field only allow : a-z 0-9"); 

      if (valid) { 
       $("#users tbody").append("<tr>" + 
       "<td>" + name.val() + "</td>" + 
       "<td>" + email.val() + "</td>" + 
       "<td>" + password.val() + "</td>" + 
       "</tr>"); 
       dialog.dialog("close"); 
      } 
      return valid; 
      } 

      dialog = $("#dialog-form").dialog({ 
      autoOpen: false, 
      height: 400, 
      width: 350, 
      modal: true, 
      buttons: { 

       Ok: function() { 
       dialog.dialog("close"); 
       } 
      }, 
      close: function() { 
       form[0].reset(); 
       allFields.removeClass("ui-state-error"); 
      } 
      }); 

      form = dialog.find("form").on("submit", function(event) { 
      event.preventDefault(); 
      addUser(); 
      }); 

      $("#create-user").button().on("click", function() { 
      dialog.dialog("open"); 
      }); 
     }); 

     </script> 
    </head> 

    <body> 
     <div id="dialog-form" title="Order Details"> 
     <p class="validateTips">Spicy Sandwitch</p> 
     <p class="validateTips">More</p> 
     <form> 
      <fieldset> 
      <label for="name">More Comments</label> 
      <p class="validateTips">Sandwitch only lettuce</p> 
      <!-- Allow form submission with keyboard without duplicating the dialog button --> 
      <input type="submit" tabindex="-1" style="position:absolute; top:-1000px"> 
      </fieldset> 
     </form> 
     </div> 
     <div id="users-contain" class="ui-widget"> 
     <h1>Order List:</h1> 
     <table id="users" class="ui-widget ui-widget-content"> 
      <thead> 
      <tr class="ui-widget-header "> 
       <th>Name/Surname</th> 
       <th>Address</th> 
       <th>Telephone</th> 
       <th>Time/Date</th> 
       <th>Order Details</th> 
       <th>Done</th> 
      </tr> 
      </thead> 
      <tbody> 
      <tr> 
       </td> 
       <td>John Doe</td> 
       <td>Lykavitou 12, 2109 Aglantzia</td> 
       <td>99123456</td> 
       <td>21:00 21/11/16</td> 
       <td> 
       <button id="create-user">Show</button> 
       </td> 
       <td align="center"> 
       <input type="checkbox" class="case" name="case" value="1" /> 
      </tr> 
      <tr> 
       </td> 
       <td>Andreas Georgiou</td> 
       <td>Grigori Auxentiou 12, 2109 Aglantzia</td> 
       <td>99654789</td> 
       <td>20:00 21/11/16</td> 
       <td> 
       <button id="create-user">Show</button> 
       </td> 
       <td align="center"> 
       <input type="checkbox" class="case" name="case" value="1" /> 
      </tr> 
      </tbody> 
     </table> 
     </div> 
    </body> 

    </html> 
+2

''및 ''은 무엇입니까? – Turnip

+0

@Turnip 나는 온라인 HTML 뷰어를 사용하고 있었고 코드를 실행할 때마다 헤드와 본문을 코드에 추가했습니다. – htmlste

+0

'create-user'가 ID로 두 번 사용됩니다. 클래스를 대신 사용하십시오. – Malk

답변

0

변경, u는에 같은 이름을 가진 두 개 이상의 ID를 사용 질수을 고정 할 수 없습니다 귀하의 웹 사이트, 대신 클래스를 사용할 수 있습니다. 유

$(".create-user") 
+0

고맙습니다. 각 팝업의 내용 (텍스트)을 다른 행으로 변경하는 방법을 알고 있습니까? 나는 각 주문마다 텍스트가 다를 것임을 의미한다. – htmlste

0

으로 제안 된 클래스에 호출해야합니다 예를

<button class="create-user">Show</button> 

의 경우와 JS, 당신은 클래스의 속성과 선택기를 사용하는 것이 좋습니다.

근무 예 : https://jsfiddle.net/Twisty/5n2h03nL/

HTML

<div id="users-contain" class="ui-widget"> 
    <h1>Order List:</h1> 
    <table id="users" class="ui-widget ui-widget-content"> 
    <thead> 
     <tr class="ui-widget-header "> 
     <th>Name/Surname</th> 
     <th>Address</th> 
     <th>Telephone</th> 
     <th>Time/Date</th> 
     <th>Order Details</th> 
     <th>Done</th> 
     </tr> 
    </thead> 
    <tbody> 
     <tr> 
     <td>John Doe</td> 
     <td>Lykavitou 12, 2109 Aglantzia</td> 
     <td>99123456</td> 
     <td>21:00 21/11/16</td> 
     <td> 
      <button id="create-user-1" class="showDialog">Show</button> 
     </td> 
     <td align="center"> 
      <input type="checkbox" class="case" name="case" value="1" /> 
     </tr> 
     <tr> 
     <td>Andreas Georgiou</td> 
     <td>Grigori Auxentiou 12, 2109 Aglantzia</td> 
     <td>99654789</td> 
     <td>20:00 21/11/16</td> 
     <td> 
      <button id="create-user-2" class="showDialog">Show</button> 
     </td> 
     <td align="center"> 
      <input type="checkbox" class="case" name="case" value="1" /> 
     </tr> 
    </tbody> 
    </table> 
</div> 

jQuery를 당신의 다른 의견에 관해서

$(".showDialog").button().on("click", function() { 
    dialog.dialog("open"); 
}); 

, 당신은 더 많은 정보를 제공해야합니다. 매번 사용자 지정 세부 정보가있는 대화 상자를 "표시"단추로 시작하려면 해당 세부 정보를 제공해야합니다. 행에 data 속성 (예 : <tr data-comments="">)을 사용하거나 데이터베이스에 AJAX 호출을 할 수 있습니다. 우리는 그 내용을 작성할 수 없으며, 단추를 클릭 할 때 세부 정보를 저장할 위치와 수집 방법을 알아야합니다.

이 질문에 관해서는, 나는 당신이 대답을 가지고 있다고 의심합니다. 그래서 나는 하나를 답으로 표시하고, 다음 호에는 찔러보고, 필요하다면 새로운 질문을 만듭니다.