如何使用thickbox(或模态窗口)更新选择输入框
我有一个带有动态选择框的表单(从数据库中提取)。我想让用户能够在不离开表单的情况下添加到该选择框。我希望当用户单击选择框旁边的链接时弹出一个厚框(或模式窗口)。厚盒弹出窗口将有一个表单,用户可以在其中输入要在选择框中显示的新值。当用户单击“提交”时,厚框(或模式)弹出窗口将关闭,并仅刷新他们要添加到的选择框...从而保留表单上的所有其他数据。作为奖励,我还希望选择框可以选择刚刚添加的值。
我找到了一些相似的例子,但没有完全相同的。我见过的最接近的是 jquery 的 AddToList 插件: http://pelicansareevil.com/jquery/ addtolist - 但它不使用厚盒样式弹出窗口。
我已经接近获得此工作的厚盒版本,但当厚盒关闭时,我似乎无法自动刷新选择框。
I have a form with a dynamic select box (pulled from a database). I want to give users the ability to add to that select box without leaving the form. I would prefer a thickbox (or modal window) to pop up when the user clicks a link next to the select box. The thickbox popup would have a form where the user can enter the new value to be displayed in the select box. When the user clicks submit, the thickbox (or modal) popup closes, and refreshes just the select box that they were adding to...thus preserving all other data on the form. As a bonus, I would also like for the select box to select the value that was just added.
I have found some close examples, but nothing quite the same. The closest thing I have seen to this is the AddToList plugin for jquery here: http://pelicansareevil.com/jquery/addtolist - but it does not use a thickbox style popup.
I have come close to getting a thickbox version of this working, but I cannot seem to refresh the select box automatically when the thickbox is closed.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
下面的代码将被插入到厚盒关闭时调用的函数中。您可能还需要添加一些代码以在关闭厚框后清除文本框。
如果你有两个像这样的输入...
那么你可以这样做...
The below code would be inserted into the function that is called when the thickbox is closed. You may also want to add some code to clear the text boxes after they close the thickbox too.
If you had two inputs like this...
Then you could do this...
我认为主要问题是当 ThickBox 关闭时你无法捕获事件。据我所知,ThickBox 本身不支持回调,您可以在回调中传递一个在模式窗口关闭时调用的函数。
不过,您可以尝试向thickbox cb_thickbox 添加此内容(将其替换为当前的ThickBox 脚本)。它为 ThickBox 插件添加了回调函数。
只需在脚本中定义此函数即可
I think the main problem was that you couldn't catch the event when the ThickBox was closed. As far as I know ThickBox doesn't natively support a callback, where you can pass a function that gets called when the modal window is closed.
However you can try this addition to thickbox cb_thickbox (replace this with your current ThickBox script). It adds a callback function for ThickBox plugin.
Just define this function in your script