在外部单击上禁用关闭模式

时间:2015-11-25 03:56:42

标签: javascript php jquery materialize

我正在制作一些使用modal(s)和 Materialisecss 的博客,但是我的模态onclick外部和虚假数据都有问题,           这是我的代码

main.js

function changepassword(){
 var user = $('#userlog').val();
 var content  = ""; 

content += '<div id="modganpas" class="modal modal-fixed-footer">';
content += '<div class="modal-content">';
content += '<form>';        
content += '<style="text-align:center;font-size:12px;font-weight:bold;"><h3>change Password</h3>';
content += '<div><i class="material-icons">supervisor_account</i>';             
content += '</div>';
content += '<div class="row">';
content += '<div class="input-field col s12">';
content += '<input id="changeUsername" name="changeUsername" type="text" class="validate" disabled>';
content += '</div>';
content += '<div class="input-field col s12">';
content += '<input id="changePasswordold" maxlength="32" name="changePasswordold" type="password" class="validate">';
content += '<label for="changePasswordold">Password old</label></div>';
content += '<div class="input-field col s6">';
content += '<input id="changePasswordnew" maxlength="32" name="changePasswordnew" type="password" class="validate">';
content += '<label for="changePasswordnew">Password new</label></div>';
content += '<div class="input-field col s6">';
content += '<input id="changePasswordnew1" maxlength="32" name="changePasswordnew1" type="password" class="validate">';
content += '<label for="changePasswordnew1">Ulangi Password</label></div>';
content += '</div>';
content += '</form>';
content += '</div>';
content += '<div class="modal-footer">';
content += '<a href="#" onClick="check_ganpass()" id="btn_ok" class="modal-action modal-close waves-effect waves-green btn-flat ">Edit</a>';
content += '<a href="#!" onClick="cancelchangePassword()" class="modal-action modal-close waves-effect waves-red btn-flat ">Cancel</a>';
content += '</div>';
content += '</div>';
content += '</div>';

        $("#formodal").append(content);
        $('#changeUsername').val(user);}


//for check


    function check_ganpass(){
    var username = $('#changeUsername').val();
    var passwordold = $('#changePasswordold').val();
    var passwordnew = $('#changePasswordnew').val();
    var passwordnew1 = $('#changePasswordnew1').val();
    var urlnyah    = 'pas.php';

    $.ajax({
        url     : urlnyah,


        data    : 'username='+username+'&passwordold='+passwordold+'&passwordnew='+passwordnew+'&passwordnew1='+passwordnew1, 
        type    : 'POST',
        dataType: 'html',
        success : function(pesan){
            if(pesan=='ok,'){
                Materialize.toast('Data Telah Berubah',4000);
            }
            else{
                Materialize.toast(pesan,4000);
            }
        }
    });}

pas.php

<?php include("connection.php");
session_start();
$username = $_POST['username'];
$passwordold = md5($_POST['passwordold']);
$passwordnew = md5($_POST['passwordnew']);
$passwordnew1 = md5($_POST['passwordnew1']);
    $query = mysql_query("select * from tuser where username ='$username' and password = '$passwordold'");
    $data = mysql_num_rows($query);
    if ($data ==1)
    {   if ($passwordnew == $passwordnew1){     mysql_query("UPDATE tuser SET password='$passwordnew1' WHERE username='$username'");
            echo "ok,";
        } else {
        echo "Password new not same";
        }}else{
        echo "Password old werong.";}?>

connection.php

<?php $sambung=mysql_connect('localhost','root', '')or die('Not connected : ' . mysql_error());
mysql_select_db("test", $sambung)or die('Not connected : ' . mysql_error());?>

问题是如何在外部点击时禁用关闭模式,如果数据错误或错误。

谢谢你的纠正。

3 个答案:

答案 0 :(得分:5)

//用于在外部点击时禁用模式

$('#modalid').openModal({dismissible:false});

//在ok按钮中删除模态动作模态 - 关闭

<a href="#" onClick="check_ganpass()" id="btn_ok" class="waves-effect waves-green btn-flat ">Edit</a>

//插入轰鸣声“Materialise.toast('Data Telah Berubah',4000);”

$('modalid').closeModal();

希望能回答你的问题。 :)

答案 1 :(得分:1)

试试这个

$('#ModalID').modal({
    backdrop: 'static',
    keyboard: false
})

或在html中设置数据属性如下

data-backdrop="static" data-keyboard="false"

弹出电话

希望这会有所帮助..

答案 2 :(得分:0)

如果只有一个模式,并且正在使用jquery,则可以执行以下操作:

$('#myModal').modal()[0].M_Modal.options.dismissible = false;
$('#myModal').modal('open');

欢呼