为什么我的功能面膜不适用?

时间:2015-05-20 11:42:37

标签: javascript jquery autocomplete controls

我对我的字段使用Mask功能(例如电话号码)以强制用户仅输入该数字。 掩码应用得很好,如果我在一次页面上写我的字段和掩码。 但是,Mask不适用,当我在两个不同的页面上编写字段和Mask时,这些是通过使用AjaxRequest函数链接的。

我应该把控制面罩放在哪里? 谢谢



			$(function()
			{
				// Masking
				$("#tel_struct").mask('(33) 9-99-99-99-99', {placeholder:'X'});
				$("#fax_struct").mask('(33) 9-99-99-99-99', {placeholder:'X'});
				$("#postalcodeInput").mask('99999', {placeholder:'X'});
				
				// Validation
				$("#sky-form").validate(
				{					
					// Règles de validation
					rules:
					{
						nom_contact:
						{
							required: false
						},
						famille_contact:
						{
							required: true
						},
						typologie:
						{
							required: true
						},
						thematique:
						{
							required: true
						},
						tel_struct:
						{
							required: true 
						},
						mail_struct:
						{
							required: true 
						},
						country:
						{
							required: true
						},
						postalcode:
						{
							required: true
						},
						place:
						{
							required: true
						},
						fax_pers:
						{
							//digits: true
						},
						
					},
										
					// Messages pour validation
					messages:
					{
						nom_contact:
						{
							required: 'Saisissez le nom du contact'
						},
						famille_contact:
						{
							required: 'Veuillez sélectionner le famille de contact'
						},
						typologie:
						{
							required: 'Veuillez sélectionner une typologie'
						},
						thematique:
						{
							required: 'Veuillez sélectionner une thématique'
						},
						mail_struct:
						{
							required: 'Saisissez une adresse email',
							email: 'Entrez une adresse email valide'
						},
						tel_struct:
						{	required: 'Saisissez un numéro de téléphone',
							digit: 'Entrez seulement des chiffres'
						},
						fax_struct:
						{
							digit: 'Entrez seulement des chiffres'
						},
						country:
						{
							required: 'Sélectionner le pays',
						},
						postalcode:
						{
							required: 'Saisissez le code postal',
						},
						place:
						{
							required: 'Saisissez la ville',
						},
						fax_pers:
						{
							digit: 'Entrez seulement des chiffres'
						},
						
					},
										
					// Ajax form submition					
					submitHandler: function(form)
					{
						$(form).ajaxSubmit(
						{
							beforeSend: function()
							{
								$('#sky-form button[type="submit"]').attr('disabled', true);
							},
							success: function()
							{
								$("#sky-form").addClass('submited');
							}
						});
					},
					
					// Do not change code below
					errorPlacement: function(error, element)
					{
						error.insertAfter(element.parent());
					}
				});
			});			
			
			
			

			

<html >
<head>

		
		<!-- Fonction JQUERY Auto-complete -->		
			<script type="text/javascript" src="js/jquery.min (2).js"></script>
			<script type="text/javascript" src="js/script (2).js"></script>
		<!-- FIN JQUERY Auto complete--> 
		
		<script src="js/jquery.validate.min.js"></script>
		<script src="js/jquery.maskedinput.min.js"></script>
</head>
  
 <body class="bg-red" onload="setDefaultCountry();">
	<!--Form------------------------------------------->
		<div class="body">
			<form action="" method="post" id="sky-form" class="sky-form">
<!-- Button that calls the second page , which contains the phone number field-->
              <h4 style="cursor:pointer" onclick="ajaxrequest('lecture_structure.php', 'message')"><u>Rechercher</u></h4>
&#13;
&#13;
&#13;

2 个答案:

答案 0 :(得分:0)

我的第二页的代码(似乎没有出现)

&#13;
&#13;
Code of my second page (does not appears just called) 
<?php
session_start();
include("connexion.php");
echo "<script src=\"js/jquery.validate.min.js\"></script>";
echo "<script src=\"js/jquery.maskedinput.min.js\"></script>";
/* Méthode PDO */
$id_struct = $_POST['id_struct'];
$sql = "SELECT count(*) FROM structure WHERE nom_contact='$id_struct'";
$result = $bdd->query($sql);
$row = $result->fetch(PDO::FETCH_NUM);
if($row[0]!=0)
    {
		//echo '<i class="fa fa-ban"></i><br /><font color="red">J\'ai trouvé la structure<br /></font>';
		
	//Lire ou Afficher les données 
$_SESSION['nom_contact']=$id_struct;
//1)on se connecte à la BDD
$reponse = $bdd->query("SELECT * FROM structure WHERE nom_contact='$id_struct'");
$donnees = $reponse->fetch(PDO::FETCH_ASSOC);	
//while ($donnees = $reponse->fetch(PDO::FETCH_ASSOC))
$desc_contact= $donnees['desc_contact'];
$nom_struct= $donnees['nom_struct'];
$nom_service= $donnees['nom_service'];
$adres_struct= $donnees['adres_struct'];
$code_postal= $donnees['code_postal'];
$ville= $donnees['ville'];
$tel_struct= $donnees['tel_struct'];
$fax_struct= $donnees['fax_struct'];
$mail_struct= $donnees['mail_struct'];	
$page_web= $donnees['page_web'];	
$thematique=$donnees['id_thematique'];
$typologie=$donnees['id_typologie'];
$pays=$donnees['id_pays'];

$reponse1 = $bdd->query('SELECT * FROM typologie'); 
$donnees1 = $reponse->fetch(PDO::FETCH_ASSOC);

$reponse2 = $bdd->query('SELECT * FROM thematique'); 
$donnees2 = $reponse->fetch(PDO::FETCH_ASSOC);

$reponse3 = $bdd->query('SELECT * FROM pays'); 
$donnees3 = $reponse->fetch(PDO::FETCH_ASSOC);
		echo '<fieldset>
	<!--Typologie-->
	<div class="row">
							<section class="col col-6">
								<label class="input">';								
								 while ($donnees1 = $reponse1->fetch(PDO::FETCH_ASSOC))
									 if ($donnees1["id_typologie"]==$typologie)
										echo' <input type="text" name="typologie" id="typologie" placeholder="Typologie" value="'.$donnees1["typologie"].'" disabled=disabled">
								</label>
								<i></i>';
												
					echo'		</section>
									
						
						<!--Fin Typologie-->
						
						<!--Thématique-->
							<section class="col col-6">
								<label class="select">
									<select id="thematique" name = "thematique">';
													
													echo '<OPTION VALUE="">Thématique</OPTION>';
													 while ($donnees2 = $reponse2->fetch(PDO::FETCH_ASSOC))
														{  if ($donnees2["id_thematique"]==$thematique)
														echo '<OPTION VALUE="'.$donnees2["id_thematique"].'" selected="selected">'.$donnees2["thematique"].'</OPTION>';
													        else
														echo '<OPTION VALUE="'.$donnees2["id_thematique"].'">'.$donnees2["thematique"].'</OPTION>';
													}
								
												
					echo'				</select>
									<i></i>
								</label>
							</section>
						<!--Fin Thématique-->
	</div>				
						<!--Nom du contact-->
							<section>
								<label class="label">Nom du contact</label>
								<label class="textarea">
									<i class="icon-append fa fa-user"></i>
									<textarea rows="2" name="nom_contact" id="nom_contact">'.$id_struct.'</textarea>
								</label>
							</section>	
						<!--Fin contact-->
				
						
					
						<!--Description contact-->
							<section>
								<label class="label">Description du contact</label>
								<label class="textarea">
									<i class="icon-append fa fa-comment"></i>
									<textarea rows="4" name="desc_contact" id="desc_contact">'.$desc_contact.'</textarea>
								</label>
							</section>	
						<!--Fin Description contact-->
					
				</fieldset>	
				
				<fieldset>	
					
						<!--Nom de la structure-->
							<section>
								<label class="input">
									<i class="icon-append fa fa-briefcase"></i>
									<input type="text" name="nom_struct" id="nom_struct" placeholder="Nom de la structure" value="'.$nom_struct.'"">
								</label>
								<i></i>
							</section>
						<!--Fin Nom de la structure-->
					
						<!--Nom du service-->
							<section>
								<label class="input">
									<i class="icon-append fa fa-briefcase"></i>
									<input type="text" name="nom_service" id="nom_service" placeholder="Nom du service / direction / pole / section de la structure" value="'.$nom_service.'">
								</label>
								<i></i>
							</section>
						<!--Fin Nom de service-->
					
					
						<!-- Adresse complète--> 
							<section>
								<label for="file" class="input">
									<input type="text" name="adres_struct" placeholder="Adresse complète" value="'.$adres_struct.'"">
								</label>
							</section>
						<!-- Fin Adresse complète-->
						<!-- code postal VILLE pays----------------------->			
					<div class="row">
						<section class="col col-3">
							<label class="input">
								<input id="postalcodeInput" name="postalcode" onblur="postalCodeLookup();" size="6" type="text" placeholder="Code Postal" value="'.$code_postal.'"">
							</label>
						</section>
						<section class="col col-4">
							<label class="input">
								<input id="placeInput" name="place" size="30" onblur="closeSuggestBox();" type="text" placeholder="Ville" value="'.$ville.'">
							</label>
							<label class="select">
								<ul class="select" style="visibility: hidden;" id="suggestBoxElement"></ul>
							</label>
						</section>
						<section class="col col-5">
							<label class="select">
								<select id="countrySelect" name="country">';
								echo '<OPTION VALUE="">Pays</OPTION>';
								while ($donnees3 = $reponse3->fetch(PDO::FETCH_ASSOC))
													{  if ($donnees3["id_pays"]==$pays)
														echo '<OPTION VALUE="'.$donnees3["id_pays"].'" selected="selected">'.$donnees3["pays"].'</OPTION>';
													        else
														echo '<OPTION VALUE="'.$donnees3["id_pays"].'">'.$donnees3["pays"].'</OPTION>';
													}
					echo'
								
								</select>
								<i></i>
							</label>
						</section>
						
					</div>



					
					<div class="row">
						<!--Tél générique-->
							<section class="col col-6">
								<label class="input">
									<i class="icon-append fa fa-phone"></i>
										<input type="tel" name="tel_struct" id="tel_struct" placeholder="Téléphone générique" value="'.$tel_struct.'">
								</label>
							</section>
						<!--Fin tél générique-->
					
						<!--Fax générique-->
							<section class="col col-6">
								<label class="input">
									<i class="icon-append fa fa-phone"></i>
										<input type="tel" name="fax_struct" id="fax_struct" placeholder="Fax générique" value="'.$fax_struct.'">
								</label>
							</section>
						<!--Fin Fax générique-->
					</div>
					
					<div class="row">
						
						<!--Email générique-->
							<section class="col col-6">
								<label class="input">
									<i class="icon-append fa fa-envelope-o"></i>
									<input type="email" name="mail_struct" id="mail_struct" placeholder="Email générique" value="'.$mail_struct.'">
								</label>
							</section>
						<!-- Fin email générique-->
						<!--Page web-->
							<section class="col col-6">
								<label class="input">
									<input type="text" name="page_web" id="page_web" placeholder="Page web" value="'.$page_web.'">
								</label>
								<i></i>
							</section>
						<!--Fin Page web-->
					</div></fieldset>
					';
					
    }
	else {
		echo "Rien trouvé !";
	}


/*-----Méthode mysql ---
	mysql_connect('localhost','croix_rouge','admin') or die(mysql_error());
    mysql_select_db('croix_rouge') or die(mysql_error());
	$id_struct = $_POST['id_struct'];
	echo"hello";
    $sql = "SELECT nom_contact FROM structure WHERE nom_contact='$id_struct'";
	echo"hello";
    $req = mysql_query($sql) or die('Erreur SQL !'.$sql.'<br>'.mysql_error()); 
	echo"hello";
    $res = mysql_num_rows($req); 
    if($res!=0)
    {
		echo '<i class="fa fa-ban"></i><br /><font color="red">J\'ai trouvé la structure<br /></font>';
    }
	else {
		echo "Rien trouvé !";
	}
*/
echo "<script src=\"js/controles.js\"></script>";
?> 
&#13;
&#13;
&#13;

答案 1 :(得分:0)

AjaxRequest函数的代码:

    function get_XmlHttp() {
      var xmlHttp = null;

      if(window.XMLHttpRequest) {        // Firefox, IE7+, Opera, Safari, ...
        xmlHttp = new XMLHttpRequest();
      }
      else if(window.ActiveXObject) {    // Internet Explorer 5 or 6
        xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
      }

      return xmlHttp;
    }

    function ajaxrequest(php_file, tagID) {
      var request =  get_XmlHttp();
      var id_struct = document.getElementById('id_struct').value;

      
	var the_data = 'id_struct='+id_struct;
	
	  request.open("POST", php_file, true);            

      request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
      request.send(the_data);

      request.onreadystatechange = function() {
        if (request.readyState == 4) {
          document.getElementById(tagID).innerHTML = request.responseText;
        }
      }
    }