问题描述
我的页面上有一个按钮.单击时应出现一个弹出框,允许用户输入文本.当按下 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.
谢谢!
推荐答案
最简单的形式,你可以使用prompt(question, default):(取自 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 将文本放入变量中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!