Javascript Alertify

Javascript Alertify

本文关键字:Alertify Javascript      更新时间:2023-09-26

我有一个htm表,位置和问题,供用户回答

<table id="position_holder">
    <tbody>
        <tr>
            <td>СБ</td>
            <td>
            <a id="6" href="/position-holder/#">Руководитель службы СБ</a>
                <div class="question">Имеете ли вы высшее образование?</div>
                <div class="question">Ваш стаж работы по специальности не менее 5 лет в правоохранительных органах ?</div>
                <div class="question">Ваш возраст от 25 до 50 лет?</div>
            </td>
        </tr>
        <tr>
            <td>Отдел безопасности объектов СБ</td>
            <td>
            <a id="7" href="/position-holder/#">Начальник отдела</a>
            </td>
        </tr>
        <tr>
            <td>ДБиОТ, ООС и ОЗ</td>
            <td>
            <a id="8" href="/position-holder/#">Директор ДБиОТ, ООС и ОЗ</a>
            <div class="question">Ваш возраст от 25 до 50 лет?</div>
                <div class="question">Ваш стаж работы по специальности не менее 5 лет (в нефтяной промышленности на руководящих должностях)?</div>
                <div class="question">Ваш стаж работы в текущей должности не менее 2 лет?</div>
                <div class="question">Есть ли у Вас в наличии высшее профессиональное (техническое)образование?</div>
                <div class="question">Ваша текущая должность в АО "КБМ", согласно оргструктуре, находится на одну ступень ниже либо является аналогичной в другом подразделении?</div>
            </td>
        </tr>
        <tr>
            <td>ДБиОТ, ООС и ОЗ</td>
            <td>
            <a id="9" href="/position-holder/#">Ведущий специалист гражданской обороны</a>
            </td>
        </tr>
    </tbody>
</table>

我有一个javascript。如果用户点击位置,他必须测试通过,并在那里提出问题。

$('#position_holder td a').on('click', function(){
    if($(this).next().text() == ''){
        alertify.alert('Tests are not set!');
    }
    $(this).parents("td").find(".question").each(function (index) {
       if(!confirm($(this).text())){
           alertify.alert('Test faild!');
           return false;
        }else if($(this).next().text() == ''){
           console.log('Test success! Ajax request started!');
           alertify.alert('Test passed!');
        }
    });
    return false;
});

它运行良好。我需要一些建筑物来确认和提醒信息。

我使用http://fabien-d.github.io/alertify.js/

警报看起来不错,但我不知道如何实现它。

我不能设置if(!alerify.confirm($(this).text())){它不工作,甚至要做它抛出循环,请帮助!

最后我自己做

        $('#position_holder td a').on('click', function(){
            if($(this).next().text() == ''){
                alertify.alert('No test here yet!');
                return false;
            }
            var questions = $(this).parents("td").find(".question").toArray();
            var posId = $(this).attr('id');
            answerTheQuestion(questions, questions.length, 0, posId);
            return false;
        });
        function answerTheQuestion(questions, num, pos, posId){
            if(num == 0){
                alertify.alert('Test done!');
                return false;
            }
            console.log(questions, num, pos, posId);
            var currentQuestion = questions[pos];
            alertify.confirm($(currentQuestion).text(), function (e) {
                if (e) {
                    // user clicked "ok"
                    answerTheQuestion(questions, num - 1, pos + 1, posId);
                } else {
                    // user clicked "cancel"
                    alertify.alert('Test failed!');
                }
            });
        }