【问题标题】:How to create a pop up window asking for input using jquery如何使用jquery创建一个要求输入的弹出窗口
【发布时间】:2015-01-02 11:03:04
【问题描述】:

我的 index.html 代码是

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>Ember Starter Kit</title>
  <link rel="stylesheet" href="css/normalize.css">
  <link rel="stylesheet" href="css/style.css">
<link rel="stylesheet" href="css/one.css">
</head>
<body>

<!--Script1-->

  <script type="text/x-handlebars">
    <div id="W">
<h1> Welcome </h1>
</div>

<div id="section1">
<h2>   {{#link-to 'DINESH'}} DINESH {{/link-to}}  </h2>
</div>

<div id="section">
<h2> {{#link-to 'HOME'}} HOME {{/link-to}} </h2> 
</div>

<div id="section2">
<h2> {{#link-to 'CLICK'}} CLICK {{/link-to}} </h2> 
</div> 

 {{outlet}}

  </script>

  <!--Script2-->

  <script type="text/x-handlebars" id='HOME'>
  <div class-'HOME'>
  <p>
    This is a sample site for practicing Ember.js 
  </p>
  </script>

  <!--Script3-->

   <script type="text/x-handlebars" id='DINESH'>
  <div class-'DINESH'>
  <p>
     I welcome you to my page.. keep in touch......!!!!!
  </p>
  VIDIYAL
<br>

   Being the "Director of Community Service" in Rotaract Club of Future League, I organised a project called "VIDIYAL" where i taught basic computer knowledge to Orphanage Students. 
  </script>

  <!--Script4-->

  <script type="text/x-handlebars" id='CLICK'>

<div class-'CLICK'>
<p> Click the button to display the information which you want: </p>

<button onclick="myFunction()">Click me</button>

<p id="CLICK"></p>

<script>
function myFunction() {
    document.getElementById("demo").innerHTML = "Hello World";
}



  </script>


  <script src="js/libs/jquery-1.10.2.js"></script>
  <script src="js/libs/handlebars-v2.0.0.js"></script>
  <script src="js/libs/ember-1.9.1.js"></script>
  <script src="js/app.js"></script>
  <!-- to activate the test runner, add the "?test" query string parameter -->
  <script src="tests/runner.js"></script>
</body>
</html>

app.js 代码是

App = Ember.Application.create();

App.Router.map(function()
{
    this.resource('HOME');
    this.resource('DINESH');
    this.resource('CLICK');
});

如果我点击它应该会显示一个弹出窗口,询问我的名字(“输入你的名字”)。

我是一名对编程非常陌生的学生。所以请尽可能简单地解释我。

【问题讨论】:

  • 你可以使用prompt
  • 亲爱的 MLeFevre,谢谢,但我应该在哪里添加该代码?而且我不需要为它创建任何模型?

标签: javascript jquery html json ember.js


【解决方案1】:

您可以在纯 javascript 中执行此操作。 prompt() 方法将为您执行此操作。 检查here

如果您想在 Ember.js 中执行此操作,您需要在用户单击时打开一个模式。 创建了一个小提琴http://jsfiddle.net/rocky_217/uxa38xjz/4/

【讨论】:

  • 不,伙计。我只需要在 ember js 中做。请告诉如何在 ember js 中进行操作。
  • 我确实试过这个.. 但是当我选择点击按钮时我得到了相同的代码。现在我应该如何将它与我的 app.js 文件连接起来?
  • Dev 先生,现在开始工作了。但问题是,弹出页面显示在 index.html 页面中。 .......当我将索引更改为单击时..仍然要求输入名称,但它不显示我输入的名称。
【解决方案2】:

您可以在 jquery 或 js 中使用 prompt() 函数来接收弹出窗口中的输入。查看代码-:

<script>

var childAge =  prompt("Enter Child  age")
alert(childAge);

</script>

【讨论】:

  • 亲爱的阿卡什。好的,但我怎样才能将它与我的 app.js 文件链接起来?请详细解释我..
  • @DineshT 首先感谢您提供 +10,好的,您可以将上面的代码直接粘贴到您的 html 页面或 app.js 中写入 var name = prompt("Enter your name") 和用户名称变量相应地作为用户输入将被存储在里面。如果您觉得麻烦,请让我更清楚 app.js 中的内容。
猜你喜欢
  • 1970-01-01
  • 2011-12-25
  • 1970-01-01
  • 1970-01-01
  • 2022-06-29
  • 1970-01-01
  • 2020-06-28
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多