可一个唯一的ID被添加到在运行时的对话框? [英] Can a unique ID be added to a dialog box at run time?

查看:154
本文介绍了可一个唯一的ID被添加到在运行时的对话框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法,以独特的价值在运行时分配给 jQuery的对话框所以我可以跟踪每个对话框单独使用分配的ID?

我想用一个电话系统,我会显示一个对话框,当有电话呼入交互。该对话框将有3个按钮供用户点击。

  1. 拿起
  2. 发送到语音邮件
  3. 忽略

如果用户点击任意三个按钮的阿贾克斯请求被发送到服务器,并在成功关闭对话框。

但是,如果用户得到另一个呼入而对话是开放的等待回应我想,以显示与另一个消息另一个对话框。但我需要分配的呼叫ID为对话框中的从服务器接收它打开之前,因此,如果用户拿起自己的身体电话不点击从对话框按钮我会送一个对话框(亲密)来一个给ID如不再需要响应用户关闭它在用户的代表。 我不希望关闭所有对话框

请注意我有服务器端的轮询来更新当前手机状态的客户端浏览器。因此采用这种我可以发出对话框(亲密),但我希望我可以通过ID,以便客户端知道关闭该对话框。

ID创建/分配的,现在在页面加载之前运行的时间。

由于我不知道会出现什么ID是之前加载页面时,我不能做这样的事情

 < D​​IV ID =PhoneCallId标题=呼入电话的风格=显示:无;>< / DIV>
 

我希望我可以分配一个唯一的编号(例如:123456)的框 beforOpen ,然后关闭箱与唯一的ID 123456。

解决方案

下面是一个示例,让你有一个模板元素使用追加拷贝到页面 .clone()。您将有这个,你需要一个新的对话框,每次做。这应该是一个开始的项目。

注:当克隆一个元素,你可以在调用前更改ID 追加(),而不会破坏你的页面

VAR idCounter = 0; $('按钮')。在('点击',函数(){     idCounter ++; //生成新的ID     VAR诊断= $('#PhoneCallId'); //获取模板     变种newDiag = $(diag.clone()); //克隆ID        newDiag.attr('身份证','PhoneCallId'+ idCounter); //更改ID     newDiag.find(dialogTitle)文本('DIAGLOG ID ='+ idCounter)。        $('#dialogPlaceHolder)追加(newDiag)。 //追加和放大器;展示下        newDiag.show(); //显示它(你可以调用.dialog或其他方法) });

&LT;脚本SRC =htt​​ps://ajax.googleapis.com/ajax /libs/jquery/2.1.1/jquery.min.js"></script> &LT;按钮&GT;!点击这里给我添加对话框&LT; /按钮&GT; &LT; D​​IV ID =PhoneCallId标题=呼入电话的风格=显示:无;&GT; DIALOG&LT;标签类=dialogTitle&GT;模板&LT; /标签&gt;&LT; / DIV&GT; &LT; D​​IV ID =dialogPlaceHolder&GT;&LT; / DIV&GT;

Is there a way to assign a unique value to a jQuery dialog box at run time so I can keep track of each dialog separately using the assigned ID?

I am trying to interact with a telephony system where I would show a dialog box when there is an inbound call. The dialog box will have 3 buttons for the user to click on.

  1. Pick Up
  2. Send To Voice Mail
  3. Ignore

if a user clicks on any of the three button an Ajax request is sent to the server and the dialog in closed on success.

However, if a user gets another inbound call while the a dialog is open "waiting for a respond" I would like to display another dialog with another message. But I would need to assigned the call id "received from the server" to a dialog box before it is opened, so if a user pick up their physical phone "without clicking on the button from the dialog" I will send a dialog('close') to a giving ID to close it on the user's behalf as the user respond is not longer needed. "I don't want to close all dialogs"

Note I have server-side polling that updates the client "browser" of the current phone status. so using this I can issue the dialog('close') but I am hoping that I can pass the ID so the client will know which dialog box to close.

ID are created/assigned at run time now before the page is loaded.

Since I don't know what will the ID be before the page is loaded I can't do something like this

<div id="PhoneCallId" Title="Inbound Call" style="display: none;"></div>

I am hoping I can assign a unique number (ex. 123456) to the box beforOpen and then close the box with the unique ID 123456.

解决方案

Here is a sample that allow you to have a Template element and append copies to the page using .clone(). You will have to do this every time you need a new dialog. That should be a start for your project.

Note : When cloning an element, you can change the id before calling append() without corrupting your page.

var idCounter=0;
$('button').on('click', function(){
    idCounter++; //Generate new ID

    var diag = $('#PhoneCallId'); //Get Template
    var newDiag = $(diag.clone()); //Clone Id
  
    newDiag.attr('id','PhoneCallId' + idCounter); //Change ID
    newDiag.find(".dialogTitle").text('DIAGLOG ID = ' + idCounter);
  
    $('#dialogPlaceHolder').append(newDiag); //Append & Show It
  
    newDiag.show(); //Show it (you can call .dialog or other methods)
});

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button>CLICK ME TO ADD DIALOG!</button>

<div id="PhoneCallId" Title="Inbound Call" style="display: none;">DIALOG <label class="dialogTitle">TEMPLATE</label></div>

<div id="dialogPlaceHolder"></div>

这篇关于可一个唯一的ID被添加到在运行时的对话框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆