admin管理员组

文章数量:1405537

How do I convert this into JQuery?

function contantForm()
{
    let Username = document.getElementById("Username").value;  //create element Id called Username
    let Emailinput = document.getElementById("Email").value; //create element Id called Emailinput
    alert("Thank you " + Username) //alerts user with thier username after clicking submit
    document.getElementById("Username").value=""; //get username Id from index page
    document.getElementById("Email").value=""; //get email Id from index page
    document.getElementById("Phone").value=""; //get phone Id from index page
}

Thanks,

How do I convert this into JQuery?

function contantForm()
{
    let Username = document.getElementById("Username").value;  //create element Id called Username
    let Emailinput = document.getElementById("Email").value; //create element Id called Emailinput
    alert("Thank you " + Username) //alerts user with thier username after clicking submit
    document.getElementById("Username").value=""; //get username Id from index page
    document.getElementById("Email").value=""; //get email Id from index page
    document.getElementById("Phone").value=""; //get phone Id from index page
}

Thanks,

Share asked Jun 7, 2020 at 6:51 nabz123nabz123 131 silver badge3 bronze badges 3
  • 3 There is nothing you need to do. It already works. – Niet the Dark Absol Commented Jun 7, 2020 at 6:52
  • Change document.getElementById("Username").value to $("#Username").value and same like all other ids. – Maniraj Murugan Commented Jun 7, 2020 at 6:55
  • The jQuery is a JavaScript library, that is, it's an extension written in pure JS. So, you don't hsve to do anything, this will work if you use jQuery as well – FZs Commented Jun 7, 2020 at 7:12
Add a ment  | 

1 Answer 1

Reset to default 4

pure JS and Jquery can work together, your code always work with or without jquery, but if you want all codes in same format then.

function contantForm()
{
    let Username = $("#Username").val();  
    let Emailinput = $("#Email").val(); 
    alert("Thank you " + Username) 
    $("#Username").val(""); 
    $("#Email").val(""); 
    $("#Phone").val(""); 
}
<script src="https://cdnjs.cloudflare./ajax/libs/jquery/3.3.1/jquery.min.js"></script>

本文标签: How to convert JavaScript to JQueryStack Overflow