2017-10-30 3 views
0

Wenn ich Javascript entferne meine Reset-Taste funktioniert gut, aber wenn ich JavaScript laden, funktioniert es nicht mehr. Ich habe auch versucht, Rest-Taste mit jQuery-Funktion. Ich habe auch versucht, mit Eingabe Typ = "Reset" Wert = "Reset" , aber es funktioniert auch nicht. Ich habe alles versucht, was ich jetzt weiß, ich weiß nicht, was ich tun soll.Reset-Taste funktioniert nicht beim Laden JavaScript

Bitte helfen

$(document).ready(function c() { 
 
    $("#f").click(function(event){ 
 
    $("body").toggleClass("hi"); 
 
    event.preventDefault(); 
 
    }); \t \t \t 
 
}); 
 

 
$(document).ready(function c1() { 
 
    $("body").click(function(event){ 
 
    $("p").toggleClass("hii"); 
 
    event.preventDefault(); 
 
    }); \t \t \t 
 
}); 
 

 
//reset funtion using jquery 
 
/*$(document).ready(function re(){ 
 
    $("form").click(function(event){ 
 
    $("#r").reset(); //reset funtion using jquery 
 
    }); \t 
 
})*/
body{ 
 
    font-size: x-large; 
 
} 
 
h2{ 
 
    color: blue; 
 
} 
 
body.hi{ 
 
    background:#242424; 
 
    color: white; 
 
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<div align="right"><input type="submit" id="f" name="night mode" value="night mode" onclick="c()" onclick="c1()"></div> 
 
<h2>contact form</h2> 
 
<form action="mailto:[email protected]" method="post" enctype="text/plain"> 
 
    <label for="company">company's name<br> 
 
    <input type="text" id="company" name="company" autocomplete="companyname" placeholder="name" > 
 
    </label><br> 
 
    <label for="contact_person">contact person<br> 
 
    <input type="text" id="contact_person" name="contact person" autocomplete="contact person" placeholder="name"> 
 
    </label><br> 
 
    <label for="email">email <br> 
 
    <input type="email" id="email" autocomplete="email" name="email" placeholder="[email protected]"> <br> 
 
    <label >Subject</label> 
 
    <br> 
 
    <textarea name="subject" placeholder="Write something.."></textarea><br> 
 
    <button type="submit" value="Submit">Submit</button> reset button 
 
    I have also tried using input type="reset" value="Reset" 
 
       but it is also not working 
 
    <button type="reset" onclick="re()" id="r">Reset</button> 
 
</form>

+0

'Reset funtion mit jquery' - möglicherweise diese Syntaxfehler mit Ihnen schraubt –

Antwort

4

Ihr Problem ist, dass Sie Ihre $(document).ready() falsch schreiben. Sie deklarieren keine aufrufbare Funktion als Parametername für ready(). Es sollte so aussehen:

$(document).ready(function() { 
    function myFunc(event) { 
     console.log("Function MyFunc() called"); 
    } 
}); 

Als nächstes sollten Sie nur eine $(document).ready() haben. JavaScript unterstützt mehrere ready() Deklarationen, aber dies füllt nur Ihren Code.

$(document).ready()

Verwandte Themen