【问题标题】:display message with array data in confirmation box [closed]在确认框中显示带有数组数据的消息[关闭]
【发布时间】:2013-06-29 10:16:53
【问题描述】:

我想在确认框中显示自定义消息,例如

var response=confirm(Are you sure you want to select these times?

1)3a.m to 4a.m

2)8a.m to 9a.m

so on...)

我在 ajax 成功的多维数组中以 json 格式从 php 页面获取此数据,我想通过迭代来显示此 json 数据,作为消息。 我得到的数据会像[{'start_time':3a.m,'end_time':4a.m}{'start_time':8a.m,'end_time':9a.m}....]

谁能帮帮我。

提前致谢

【问题讨论】:

  • 您基本上是想显示一个确认对话框,让用户在各种答案之间进行选择?
  • 用户之前已经选择了那个时间。它只是用于确认是或否
  • @KumariManisha:你考虑过config()吗?

标签: php javascript confirmation


【解决方案1】:
var data = [{'start_time':'3a.m','end_time':'4a.m'},{'start_time':'8a.m','end_time':'9a.m'}];

var alertText = "Are you sure you want to select these times?\n"
for(var i in data) {
    alertText += data[i].start_time+ " to "+ data[i].end_time +"\n";
}
var response = confirm( alertText );

你可以这样做。这是你想要的显示警报。我只给你一个使用你的数据的例子。

【讨论】:

    【解决方案2】:

    您可以使用 handlebars 之类的模板引擎。

    1. 您已经使用 ajax 从服务器获取数据。

    2. 你通过把手定义一个模板,比如

      <script id="unit-template" type="text/x-handlebars-template">
         <div id="urDataWillExapndedHere">
              <ul>
               {{#each data}}
                <li>
                  Time:      '{{this.date}}'               
                </li>
               {{/each}}
               </ul>
            </div>
       </script>
      

    3.你编译脚本把数据放到模板中,然后得到一个html结果。

    4.你把你的 html 使用 innderHtml() 或 jquery html() 或任何你喜欢的东西放到一个 html 元素中

    5.使用确认对话框显示该元素

    【讨论】:

      猜你喜欢
      • 2017-07-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多