我已经阅读了jquery上的教程,但我很难理解有人能教我更容易些,我希望当我按下其中一个按钮时,它的值将显示在valuefrommybutton中,当模式弹出时,我可以键入文本,在clic之后k好,我输入的文本将放在valuefrommymodal上。

<!DOCTYPE HTML>
    <html lang="en">
    <head>
        <meta charset="utf-8">
    </head>
    <body>
        <input id="btn1" type="button" value="1">
        <input id="btn2" type="button" value="2">
        <input id="btn3"type="button" value="3">

        <input id="valueFromMyModal" type="text">

        <!--How to make this pop up modal form-->
        <div id="myform">
            <form>
<label id="valueFromMyButton"></label>
            <input id="name" type="text">
            <input id="btnOK" type="button" value="Ok">
            </form>
        </div>
</body>
</html>

最佳答案

我已经把上面查询的完整箱子放在这里了。您也可以查看演示链接。
演示:http://codebins.com/bin/4ldqp78/2/How%20to%20make%20a%20simple%20modal%20pop
HTML

<div id="panel">
  <input type="button" class="button" value="1" id="btn1">
  <input type="button" class="button" value="2" id="btn2">
  <input type="button" class="button" value="3" id="btn3">
  <br>
  <input type="text" id="valueFromMyModal">
  <!-- Dialog Box-->
  <div class="dialog" id="myform">
    <form>
      <label id="valueFromMyButton">
      </label>
      <input type="text" id="name">
      <div align="center">
        <input type="button" value="Ok" id="btnOK">
      </div>
    </form>
  </div>
</div>

JQuery
$(function() {
    $(".button").click(function() {
        $("#myform #valueFromMyButton").text($(this).val().trim());
        $("#myform input[type=text]").val('');
        $("#myform").show(500);
    });
    $("#btnOK").click(function() {
        $("#valueFromMyModal").val($("#myform input[type=text]").val().trim());
        $("#myform").hide(400);
    });
});

CSS
.button{
  border:1px solid #333;
  background:#6479fd;
}
.button:hover{
  background:#a4a9fd;
}
.dialog{
  border:5px solid #666;
  padding:10px;
  background:#3A3A3A;
  position:absolute;
  display:none;
}
.dialog label{
  display:inline-block;
  color:#cecece;
}
input[type=text]{
  border:1px solid #333;
  display:inline-block;
  margin:5px;
}
#btnOK{
  border:1px solid #000;
  background:#ff9999;
  margin:5px;
}

#btnOK:hover{
  border:1px solid #000;
  background:#ffacac;
}

演示:http://codebins.com/bin/4ldqp78/2/How%20to%20make%20a%20simple%20modal%20pop

07-26 04:43