2015-05-10 2 views
0

JQuery шаги: где поставить этот код

<?php 
 
function htm_admin_header() 
 
{ 
 
\t global $language_adm; 
 
\t 
 
?> 
 

 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
 
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr-FR" lang="fr-FR"> 
 

 
<head> 
 

 

 
    <script src="assets/js/jquery-1.9.1.min.js"></script> 
 
    <script src="assets/js/jquery.steps.js"></script> 
 
    <script src="assets/js/jquery.js"></script> 
 
    <script> $(document).ready(function() { 
 
     var form = $("#example-advanced-form").show(); 
 
    
 
form.steps({ 
 
    headerTag: "h3", 
 
    bodyTag: "fieldset", 
 
    transitionEffect: "slideLeft", 
 
    onStepChanging: function (event, currentIndex, newIndex) 
 
    { 
 
     // Allways allow previous action even if the current form is not valid! 
 
     if (currentIndex > newIndex) 
 
     { 
 
      return true; 
 
     } 
 
     // Forbid next action on "Warning" step if the user is to young 
 
     if (newIndex === 3 && Number($("#age-2").val()) < 18) 
 
     { 
 
      return false; 
 
     } 
 
     // Needed in some cases if the user went back (clean up) 
 
     if (currentIndex < newIndex) 
 
     { 
 
      // To remove error styles 
 
      form.find(".body:eq(" + newIndex + ") label.error").remove(); 
 
      form.find(".body:eq(" + newIndex + ") .error").removeClass("error"); 
 
     } 
 
     form.validate().settings.ignore = ":disabled,:hidden"; 
 
     return form.valid(); 
 
    }, 
 
    onStepChanged: function (event, currentIndex, priorIndex) 
 
    { 
 
     // Used to skip the "Warning" step if the user is old enough. 
 
     if (currentIndex === 2 && Number($("#age-2").val()) >= 18) 
 
     { 
 
      form.steps("next"); 
 
     } 
 
     // Used to skip the "Warning" step if the user is old enough and wants to the previous step. 
 
     if (currentIndex === 2 && priorIndex === 3) 
 
     { 
 
      form.steps("previous"); 
 
     } 
 
    }, 
 
    onFinishing: function (event, currentIndex) 
 
    { 
 
     form.validate().settings.ignore = ":disabled"; 
 
     return form.valid(); 
 
    }, 
 
    onFinished: function (event, currentIndex) 
 
    { 
 
     alert("Submitted!"); 
 
    } 
 
}).validate({ 
 
    errorPlacement: function errorPlacement(error, element) { element.before(error); }, 
 
    rules: { 
 
     confirm: { 
 
      equalTo: "#password-2" 
 
     } 
 
    } 
 
}); 
 
    });</script> 
 
    
 

 
    
 
    
 
<link href="style/jquery.mCustomScrollbar.css" rel="stylesheet" type="text/css" /> 
 
</head> 
 
<body> 
 
    
 

 
        </li> 
 
        <li> 
 
         <a href="#"> <strong> 
 
         <?php if (isset($_SESSION['login'])) { 
 

 
          echo $_SESSION['login']; 
 
         } 
 
         elseif (isset($_COOKIE['login'])) { 
 
          echo $_COOKIE['login']; 
 
         } 
 

 

 
         ?> </strong></a> 
 
        </li> 
 

 
        <li> 
 
         <a class="active-menu" href="index.html"><i class="fa fa-dashboard "></i>Dashboard</a> 
 
        </li> 
 
        
 
<?php

Я обнаружить этот плагин, но я не знаю, как интегрирующий на моей странице. где я должен поставить код javascript и ниже и как? Я должен поместить тот же файл, что и HTML, или я должен поместить его в файл jquery-steps.js.

var form = $("#example-advanced-form").show(); 
 
    
 
form.steps({ 
 
    headerTag: "h3", 
 
    bodyTag: "fieldset", 
 
    transitionEffect: "slideLeft", 
 
    onStepChanging: function (event, currentIndex, newIndex) 
 
    { 
 
     // Allways allow previous action even if the current form is not valid! 
 
     if (currentIndex > newIndex) 
 
     { 
 
      return true; 
 
     } 
 
     // Forbid next action on "Warning" step if the user is to young 
 
     if (newIndex === 3 && Number($("#age-2").val()) < 18) 
 
     { 
 
      return false; 
 
     } 
 
     // Needed in some cases if the user went back (clean up) 
 
     if (currentIndex < newIndex) 
 
     { 
 
      // To remove error styles 
 
      form.find(".body:eq(" + newIndex + ") label.error").remove(); 
 
      form.find(".body:eq(" + newIndex + ") .error").removeClass("error"); 
 
     } 
 
     form.validate().settings.ignore = ":disabled,:hidden"; 
 
     return form.valid(); 
 
    }, 
 
    onStepChanged: function (event, currentIndex, priorIndex) 
 
    { 
 
     // Used to skip the "Warning" step if the user is old enough. 
 
     if (currentIndex === 2 && Number($("#age-2").val()) >= 18) 
 
     { 
 
      form.steps("next"); 
 
     } 
 
     // Used to skip the "Warning" step if the user is old enough and wants to the previous step. 
 
     if (currentIndex === 2 && priorIndex === 3) 
 
     { 
 
      form.steps("previous"); 
 
     } 
 
    }, 
 
    onFinishing: function (event, currentIndex) 
 
    { 
 
     form.validate().settings.ignore = ":disabled"; 
 
     return form.valid(); 
 
    }, 
 
    onFinished: function (event, currentIndex) 
 
    { 
 
     alert("Submitted!"); 
 
    } 
 
}).validate({ 
 
    errorPlacement: function errorPlacement(error, element) { element.before(error); }, 
 
    rules: { 
 
     confirm: { 
 
      equalTo: "#password-2" 
 
     } 
 
    } 
 
});

HTML файл

function htm_ajout_livraison(){ 
 
?> 
 

 
     
 
<div id="page-wrapper" class="page-wrapper-cls"> 
 
    <div id="page-inner"> 
 
    
 
<form id="example-advanced-form" action="#"> 
 
    <h3>Account</h3> 
 
    <fieldset> 
 
     <legend>Account Information</legend> 
 
    
 
     <label for="userName-2">User name *</label> 
 
     <input id="userName-2" name="userName" type="text" class="required"> 
 
     <label for="password-2">Password *</label> 
 
     <input id="password-2" name="password" type="text" class="required"> 
 
     <label for="confirm-2">Confirm Password *</label> 
 
     <input id="confirm-2" name="confirm" type="text" class="required"> 
 
     <p>(*) Mandatory</p> 
 
    </fieldset> 
 
    
 
    <h3>Profile</h3> 
 
    <fieldset> 
 
     <legend>Profile Information</legend> 
 
    
 
     <label for="name-2">First name *</label> 
 
     <input id="name-2" name="name" type="text" class="required"> 
 
     <label for="surname-2">Last name *</label> 
 
     <input id="surname-2" name="surname" type="text" class="required"> 
 
     <label for="email-2">Email *</label> 
 
     <input id="email-2" name="email" type="text" class="required email"> 
 
     <label for="address-2">Address</label> 
 
     <input id="address-2" name="address" type="text"> 
 
     <label for="age-2">Age (The warning step will show up if age is less than 18) *</label> 
 
     <input id="age-2" name="age" type="text" class="required number"> 
 
     <p>(*) Mandatory</p> 
 
    </fieldset> 
 
    
 
    <h3>Warning</h3> 
 
    <fieldset> 
 
     <legend>You are to young</legend> 
 
    
 
     <p>Please go away ;-)</p> 
 
    </fieldset> 
 
    
 
    <h3>Finish</h3> 
 
    <fieldset> 
 
     <legend>Terms and Conditions</legend> 
 
    
 
     <input id="acceptTerms-2" name="acceptTerms" type="checkbox" class="required"> <label for="acceptTerms-2">I agree with the Terms and Conditions.</label> 
 
    </fieldset> 
 
</form> 
 
</div> 
 
</div> 
 

 
<?php 
 
} 
 
?>

ответ

0

Поместите свой код в script теге, а внутри $(document).ready(), и не забудьте включить плагин, например:

<html> 
<head> 
    <script src="https://code.jquery.com/jquery-1.9.1.min.js"></script> 
    <script src="plugin.js"></script> 
    <script> 
    $(document).ready(function() { 
     // your code 
    }); 
    </script> 
</head> 
<body> 
    ... 
</body> 
</html> 
+0

Да, но он не работает, когда я нажимаю кнопку дальше, ничего не происходит – Snapz

+0

Это другой вопрос. Вы спросили, где поставить этот код. –

+0

И вы изменили свой код в соответствии с вашей разметкой? Например, вам, скорее всего, потребуется изменить '$ (" # example-advanced-form "). Show();'. –

Смежные вопросы