如何通过弹出窗口输入并通过javascript / jquery将文本放在变量中 [英] How to get input via a popup and place text in a variable via javascript/jquery
问题描述
我的页面上有一个按钮。单击时,将出现一个允许用户输入文本的弹出框。当按下OK / Submit时,我的jscript将使用输入的数据执行一些功能。非常简单,但我无法弄清楚如何做到这一点。
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 using that inputted data. Very straightforward, but I just can't figure out how to do this.
谢谢!
推荐答案
以最简单的形式,您可以使用提示(问题,默认):
(取自w3schools: http://www.w3schools.com/js/tryit.asp?filename=tryjs_prompt )
in it's simplest form, you could use prompt(question, default): (taken from w3schools: http://www.w3schools.com/js/tryit.asp?filename=tryjs_prompt)
function myFunction(){
var x;
var name=prompt("Please enter your name","Harry Potter");
if (name!=null){
x="Hello " + name + "! How are you today?";
alert(x);
}
}
其他任何需要大量javascript& CSS用于创建带按钮的图层并单击这些按钮上的事件
anything else would require lots of javascript & CSS to create layers with buttons and click events on those buttons
这篇关于如何通过弹出窗口输入并通过javascript / jquery将文本放在变量中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!