【问题标题】:Can someone help fix my Alertify JS code?有人可以帮助修复我的 Alertify JS 代码吗?
【发布时间】:2019-09-15 15:43:28
【问题描述】:

我已经尝试了 3 个小时来让我的 Alertify JS 代码正常工作。我需要这些函数彼此紧随其后,并使提示的答案成为我可以在另一个函数中使用的全局变量。当我运行它时会发生什么,它会执行第一个提示,但我不执行任何其他提示。我对编码还是很陌生,我敢打赌我做了一些愚蠢的事情。这就是我所拥有的。

function appchange() {
alertify.prompt("Enter the number of the app you want to  change. From left to right, 1-5.", ' '
           , function(evt, a) { numb = a;
                              linkURL();
                              });
}
function linkURL() {
alertify.prompt("Enter the link you want the app to go to.", 'https://'
           , function(evt, b) { url = b;
                              iconHTML(); 
                              });
}
function iconHTML() {
alertify.prompt("Enter the html of the icon from fontawesome.com/icons or you can use a capitol letter. CAN NOT BE A PRO ICON!", ' '
           , function(evt, c) { icon = c;
                              finish(); 
                              });
}
function finish() {
}

如果有人能解决我做错的事情,那就太棒了。谢谢!

【问题讨论】:

  • 你还有调用appchange()的代码吗?
  • 整个架构并不真正适合这个,也不适合用户。您应该在第一次输入后放置一些 console.log 语句以查看“a”内部的内容。更好的方法是让 alertify 显示一个简单的表单。获得所有 3 个变量。可能看起来不那么酷,但更方便。一个电话,一切搞定。
  • 我从一个 html 按钮调用 appchange。
  • @ThomasLudewig 如何在 Alertify 中制作表单
  • 我认为你想要的是启动 appchange 提示,然后在回调中启动第二个提示 (linkURL())。但是我在开发者工具中看到的是第一个提示/警报被添加到 DOM 中。并且在提交输入后,提示/警报被隐藏但没有被破坏。我想你想做的这个库是不可能的(我不确定,因为这是我第一次看到它)。

标签: javascript alertify alertifyjs


【解决方案1】:

来自 alertify 文档...Alertify examples (RTFM)

            /**
             * Dialogs factory 
             *
             * @name      {string}   Dialog name.
             * @Factory   {Function} Dialog factory function.
             * @transient {Boolean}  Indicates whether to create a singleton or transient dialog.
             * @base      {String}   The name of an existing dialog to inherit from.
             *
             * alertify.dialog(name, Factory, transient, base)
             *
             */

            if(!alertify.myAlert){
              //define a new dialog
              alertify.dialog('myAlert',function factory(){
                return{
                  main:function(message){
                    this.message = message;
                  },
                  setup:function(){
                      return { 
                        buttons:[{text: "cool!", key:27/*Esc*/}],
                        focus: { element:0 }
                      };
                  },
                  prepare:function(){
                    this.setContent(this.message);
                  }
              }});
            }



            //launch it. NOTE THIS IS A STRING WITH TEXT BUT COULD ALSO BE A STRING 
            //WITH THE HTML OF YOUR FORM

            alertify.myAlert("Browser dialogs made easy!");

你也可以尝试这样的事情 - 我今天很懒所以找一个工作表单样本也许是谷歌的奇才。

 <template id="myform">
    <h2>Flower</h2>
    <form name="free_willy" >  
       <input name="something" id="something" type text>
    </form>
 </template>

而不是现代标签(见Template Tag) 你也可以使用:

     <div id="myform" hidden>
        <form>  ....
        </form>
     </div>  

现在你可以做这样的事情了

    var form_src=document.getElementById("myform").innerHTML;
    alertify.myAlert(form_src);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-02-19
    • 2014-01-25
    • 1970-01-01
    • 2013-04-01
    • 2017-05-26
    • 2014-02-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多