How to convert JavaScript to JQuery? - Stack Overflow

How do I convert this into JQuery?function contantForm(){let Username = document.getElementById("

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>

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744918754a4600998.html

相关推荐

  • How to convert JavaScript to JQuery? - Stack Overflow

    How do I convert this into JQuery?function contantForm(){let Username = document.getElementById("

    1天前
    60

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信