How to get input via a popup and place text in a variable via javascript/jquery

前端 未结 2 1539
误落风尘
误落风尘 2021-02-08 20:49

I have a button on my page. When clicked a popup box should appear allowing the user to enter text. When OK/Submit is pressed, my jscript will then perform some functions usin

2条回答
  •  我在风中等你
    2021-02-08 21:20

    Paste this code inside your head tags between script tags

    HTML

    JS

    window.onload=function()
    {
        var el=document.getElementById('button');
        el.onclick=function(){
            var my_text=prompt('Enter text here');
            if(my_text) alert(my_text); // for example I've made an alert
        }
    }
    

    DEMO.

提交回复
热议问题