多个输入框 - alertifyjs/Jquery [英] Multiple input boxes - alertifyjs / Jquery

查看:27
本文介绍了多个输入框 - alertifyjs/Jquery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用具有多个输入框的 alertifyjs 创建一个提示对话框.我设法创建了显示多个框的对话框,但我似乎无法引用用户提供的输入.

I am trying to create a prompt dialog box using alertifyjs that has multiple input boxes. I have managed to create the dialog box to show the multiple boxes but I cant seem to make a reference to the inputs that user provides.

我想编写 if 语句,当用户按下 OK 时根据用户输入执行操作.但是,确定"按钮似乎不起作用,并且 if 语句也不起作用.我不确定我可能做错了什么,有人可以帮助我.

I want to write if statement that carries out action based on user input when they press OK. However, the OK button doesnt seem to be working and also the if-statements don't work as well. I am not sure what I might be doing wrong, can someone please help me.

下面是我的代码:

<!DOCTYPE html>
<html>
<head>
     <link rel="stylesheet" href="//cdn.jsdelivr.net/npm/alertifyjs@1.11.1/build/css/alertify.min.css"/>
    <link rel="stylesheet" href="//cdn.jsdelivr.net/npm/alertifyjs@1.11.1/build/css/themes/bootstrap.min.css"/>
    <script src="//cdn.jsdelivr.net/npm/alertifyjs@1.11.1/build/alertify.min.js"></script>


</head>

<body> 

<div style="display:none;" >
    <div id="dlgContent">
        <p> Enter Value One </p>
        <input class="ajs-input" id="inpOne" type="text" value="Input One Default Value"/> 

        <p> Enter Value Two </p>
        <input class="ajs-input" id="inpTwo" type="text" value="Input two default Value"/> 

    </div>
</div>

<!-- the script  -->

<script>
  var dlgContentHTML = $('#dlgContent').html();

$('#dlgContent').html(""); 
alertify.confirm(dlgContentHTML).set('onok', function(closeevent, value) { 
                    var inpOneVal = $('#inpOne').val();
                    var inpTwoVal = $('#inpTwo').val();
                    updateListItems(inpOneVal,inpTwoVal);   
                  if (inpOneVal == "test" && inpTwoVal == "test") {
                      alertify.success('Successful');
                   } else {
                      alertify.error('Wrong')

                    }
                }).set('title',"Update");
 </script>

</body>   
</html>

JSfiddle 链接:http://jsfiddle.net/1qouxdkc/4/p>

Link to JSfiddle: http://jsfiddle.net/1qouxdkc/4/

推荐答案

在你的脚本中调用一个名为 updateListItems(inpOneVal,inpTwoVal);

In your script you call a function named updateListItems(inpOneVal,inpTwoVal);

由于该函数未在任何地方声明,因此会出错,因此暂时将其注释掉,它可以工作.

As that function is not declared anywhere, it errors, so with that temporarily commented out, it works.

堆栈片段

<html>

<head>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/alertifyjs@1.11.1/build/css/alertify.min.css" />
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/alertifyjs@1.11.1/build/css/themes/bootstrap.min.css" />
  <script src="https://cdn.jsdelivr.net/npm/alertifyjs@1.11.1/build/alertify.min.js"></script>

</head>

<body>

  <div style="display:none;">
    <div id="dlgContent">
      <p> Enter Value One </p>
      <input class="ajs-input" id="inpOne" type="text" value="Input One Default Value" />

      <p> Enter Value Two </p>
      <input class="ajs-input" id="inpTwo" type="text" value="Input two default Value" />

    </div>
  </div>

  <!-- the script  -->

  <script>
    var dlgContentHTML = $('#dlgContent').html();

    $('#dlgContent').html("");
    alertify.confirm(dlgContentHTML).set('onok', function(closeevent, value) {
      var inpOneVal = $('#inpOne').val();
      var inpTwoVal = $('#inpTwo').val();
      //updateListItems(inpOneVal,inpTwoVal);	

      if (inpOneVal == "test" && inpTwoVal == "test") {
        alertify.success('Successful');
      } else {
        alertify.error('Wrong')

      }
    }).set('title', "Update");
  </script>

</body>

</html>

这篇关于多个输入框 - alertifyjs/Jquery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆