[Javascript] Simulare click / touch su mobile

DavideSerafini

Nuovo Utente
18 Gen 2017
4
0
1
29
Salve, vorrei sapere come poter simulare il tocco su un dispositivo tablet / smartphone.
L'operazione dovrebbe cliccare in automatico all'apertura della pagina una div con inserimento in input number, in modo tale da aprire subito il tastierino numerico sul dispositivo per l'inserimento dei valori.
Su pc funziona la funzione :

$(document).ready(function(){
$('#id_campo_input').trigger('click');
});

Ma su dispositivi mobili non apre il tastierino..
Se applico la funzione a una div normale con l'href il click funziona bene...
 
Ciao, hai provato cosi ?
Codice:
$(document).ready(function(){
          $('#id_campo_input').click();
});

deve esserci da qualche parte la funzione
Codice:
$('#id_campo_input').click(function(){
 // apri tastiera
});
 
Sisi io uso il trigger click di jquery, ma con i campi input non va. Ho scoperto che é il DOM che non permette l attivazione automatica dei campi input per motivi di sicurezza. Grazie lostesso.
 
giusto, puoi richiamare la tastiera direttamente ?
Codice:
$(document).ready(function(){
         // apri tastiera
});
 
buongiorno a tutti
ho appena cominciato un corso di javascript html e css
il nostro prof ci ha dato un esercizio per convalidare un form ho fatto sia la parte html e css ma non riesco a convalidare il form con il javascript e nn so dove c'e l'errore qualcuno riesci ad aiutarmi
questo e il codice html e javascript in unico file

<!DOCTYPE HTML>

<html>

<head>
<title>Modello di registrazione</title>
<link rel="stylesheet" type="text/css" href="Modello_Registrazione.css">
<script type='text/javascript'>
function validateName(nome) {

var re = /[a-zA-Z]$/;
if(re.test(document.modulo.getElementById("nome").value)){
document.modulo.getElementById("nome").style.background = '#ccffcc';
return true;

}else{

document.modulo.getElementById("nome").style.background = '#e35152';
return false;
}

}
function validateSurname(cognome) {

var re = /[a-zA-Z]$/;
if(re.test(document.modulo.getElementById("cognome").value)){
document.modulo.getElementById("cognome").style.background = '#ccffcc';
return true;

}else{

document.modulo.getElementById("cognome").style.background = '#e35152';
return false;
}

}
function validateEmail(email){
var re = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
if(re.test(document.modulo.getElementById("email").value)){

document.modulo.getElementById("email").style.background = '#ccffcc';
return true;

}else{
document.modulo.getElementById("email").style.background = '#e35152';
return false;


}
}
function validateDataNascita(datanascita){


var re = /^\d{1,2}\/\d{1,2}\/\d{4}$/;
if(!re.test(document.modulo.getElementById("datamascita").value)){
document.modulo.getElementById("datamascita").style.background = '#e35152';
return false;
}else{
document.modulo.getElementById("datamascita").style.background = '#ccffcc';
return true;
}
var parts = dateString.split("/");
var day = parseInt(parts[1], 10);
var month = parseInt(parts[0], 10);
var year = parseInt(parts[2], 10);


if(year < 1000 || year > 3000 || month == 0 || month > 12){
return false;
}
var monthLength = [ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 ];


if(year % 400 == 0 || (year % 100 != 0 && year % 4 == 0)){
monthLength[1] = 29;


return day > 0 && day <= monthLength[month - 1];
}
}
function validateUsername(username){
var re = /[a-zA-Z]$/
var uInput = /^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[#?!@$%^&*-])/;
if(uInput.test(document.modulo.getElementById("username").value)){
document.modulo.getElementById("username").style.background = '#ccffcc';
return true;
}
if(re.test(document.modulo.getElementById("username").value)){
document.modulo.getElementById("username").style.background = '#ccffcc';
alert ("Username must contain two letters from name,two letters from surname and the year of your birthday");
return false;

}

}
function validateSex(msex,fsex)
{
x=0;

if(dovument.modulo.getElementById("msex").checked)
{
x++;
} if(document.modulo.getElementById("fsex").checked)
{
x++;
}
if(x==0)
{
alert('Select Male/Female');
return false;
}

}
function validatePassword(pwd1,8,20)
{
var pwd_len = document.modulo.getElementById("pwd1").value.length;
if (pwd_len == 0 ||pwd_len >= 20 || pwd_len < 8)
{
alert ("Password should not be empty / length be between "8" to "20" ");

return false;
}
return true;
if(pwd_len == 8){
alert ("Weak password");
}
if(pwd_len == 15){
alert ("Good password");
}
if(pwd_len == 20){
alert ("Very strong password");
}
}
function validateConfirmaPassword(pwd2,8.20)
{
var pwd_len = document.modulo.getElementById("pwd2").value.length;
if (pwd_len == 0 ||pwd_len >= 20 || pwd_len < 7)
{
alert ("Password should not be empty / length be between "8" to "20" ");

return false;
}
return true;
if(pwd_len == 8){
alert ("Weak password");
}
if(pwd_len == 15){
alert ("Good password");
}
if(pwd_len == 20){
alert ("Very strong password");
}
}
function validateForm() {
var nome = document.modulo.getElementById('nome').value;
var cognome = document.modulo.getElementById('cognome').value;
var email = document.modulo.getElementById('email').value;
var datanascita = document.modulo.getElementById('datanascita').value;
var username = document.modulo.getElementById('username').value;
var sesso1 = document.modulo.getElementById('msex').value;
var sesso2 = document.modulo.getElementById('fsex').value;
var password = document.modulo.getElementById('pwd1').value;
var confermaPassword = document.modulo.getElementById('pwd2').value;

if(validateName(nome)){
if(validateSurname(cognome)){
if(validateEmail(email)){
if(validateDataNascita(datanascita)){
if(validateUsername(username)){
if(validateSex(sesso1,sesso2)){
if(validatePassword(password)){
if(validateConfermaPassword(confermaPassword)){
return true;
}
}
}
}
}
}
}
}

return false;

}
</script>
</head>

<body>
<h1>Registrazione</h1>
<br/>
<form action="" name="modulo" onsubmit="return validateForm()">
<fieldset>
<legend>Dati : </legend>
<table border="0">
<tr>
<td>Nome : </td><td><input type="text" id="nome" /></td>
</tr>
<tr>
<td>Cognome :</td><td><input type="text" id="cognome" /></td>
</tr>
<tr>
<td>E_mail : </td><td><input type="text" id="email" /></td>
</tr>
<tr>
<td>Data di nascita : </td><td><input type="date" id:"datanascita" /></td>
</tr>
<tr>
<td>UserName : </td><td><input type="text" id="username" /></td>
</tr>
<tr>
<td rowspan="2">Sesso : </td><td><input type="radio" id="msex" />M</td>

</tr>
<tr>
<td><input type="radio" id="fsex" />F</td>
</tr>
<tr>
<td>Password : </td><td><input type="password" id="pwd1" /></td>
</tr>
<tr>
<td>Conferma Password : </td><td><input type="password" id="pwd2" /></td>
</tr>
<tr>
<td colspan="2" align="middle"><input type="submit" value="SUBMIT" /></td>
</tr>
</table>
</fieldset>
</form>

</body>

</html>
 
Ciao Ahmed, prova a contattare lo staff di ************, loro hanno risolto il mio problema subito, rispondono sempre e fanno guide su css js e html
 
Ultima modifica di un moderatore:

Discussioni simili