模式对话框未显示正确的信息
这是我的动作脚本
action.js
function showDistrict() { //alert("hello");
$.ajax({
url: 'dialog_applet.jsp#dialog-modal-district',
success: function(msg) {
document.getElementById("dialog-content-district").innerHTML = msg;
}
});
$(function() {
$("#dialog:ui-dialog").dialog("destroy");
$("#dialog-content-district").dialog({
height: 300,
width: 350,
modal: true
});
});
// alert("hello1");
}
function showCity() { //alert("hello");
$.ajax({
url: 'dialog_applet.jsp#dialog-modal-city',
success: function(msg) {
document.getElementById("dialog-content-city").innerHTML = msg;
}
});
$(function() {
$("#dialog:ui-dialog").dialog("destroy");
$("#dialog-content-city").dialog({
height: 300,
width: 350,
modal: true
});
});
// alert("hello1");
}
这是我的内容脚本,位于 dialog_applet.jsp 内,
<div id="dialog-modal-district">
dialog-modal-district is here
</div>
<div id="dialog-modal-city">
dialog-modal-city is here
/applet>
调用任何一个函数 showDistrict()或showCity()。它显示了
的内容。但是,我想检索已被调用的特定
内容。我的意思是在调用 showDistrict 时,它只会显示 dialog-modal-district is here,但它显示 dialog-modal-district is hereDialog-模态城市在这里任何帮助表示赞赏! 提前致谢。 !!
this is my action script
action.js
function showDistrict() { //alert("hello");
$.ajax({
url: 'dialog_applet.jsp#dialog-modal-district',
success: function(msg) {
document.getElementById("dialog-content-district").innerHTML = msg;
}
});
$(function() {
$("#dialog:ui-dialog").dialog("destroy");
$("#dialog-content-district").dialog({
height: 300,
width: 350,
modal: true
});
});
// alert("hello1");
}
function showCity() { //alert("hello");
$.ajax({
url: 'dialog_applet.jsp#dialog-modal-city',
success: function(msg) {
document.getElementById("dialog-content-city").innerHTML = msg;
}
});
$(function() {
$("#dialog:ui-dialog").dialog("destroy");
$("#dialog-content-city").dialog({
height: 300,
width: 350,
modal: true
});
});
// alert("hello1");
}
this is my content script which is inside of dialog_applet.jsp
<div id="dialog-modal-district">
dialog-modal-district is here
</div>
<div id="dialog-modal-city">
dialog-modal-city is here
/applet>
on call of any one function showDistrict() or showCity(). it is showing contents of both <div>
. But, i want to retrieve the particular <div>
contents, which has been called. I mean on call of showDistrict, it will only show the dialog-modal-district is here, but it is showing dialog-modal-district is here dialog-modal-city is here
Any help appreciated !!
Thanks in advance. !!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果我正确地回答了你的问题,我相信在调用函数
showCity()
时,你将得到 ajax 响应作为两个 div 的内部内容,即对话框模态区和对话框模态城市。这是因为您只是加载 urldialog_applet.jsp#dialog-modal-city,它将返回dialog_applet.jsp 页面的全部内容,而不仅仅是#dialog-modal-city div 内容。
您可以将 div 名称作为参数与 URL 一起传递,根据传递的 URL,您可以生成 ajax 响应。
If I got your question correctly, I believe on call of function
showCity()
, you will be getting ajax repsonse as the inner content of both divs, namely,dialog-modal-district and dialog-modal-city. This is because you are just loading the url dialog_applet.jsp#dialog-modal-city, which will return entire content of dialog_applet.jsp page and not just #dialog-modal-city div content.
You can pass the div name as parameter along with URL, depending upon the URL passed you can generate the ajax response.
我现在明白问题所在了。
不幸的是,使用 url
dialog_applet.jsp#dialog-modal-district
将完全加载 jsp 页面的内容,而不仅仅是您指定的片段。您有两种选择来实现您想要的目标。
提取您想要插入到对话框中的实际内容。 ajax 请求将加载完整的 jsp 页面,使用 .find() 方法您可以选择您感兴趣的部分并将其附加到您的对话框中:
使用 .load() 来自 jQuery 的方法。它的作用是从指定的 url 加载内容,并允许使用类似于您尝试使用的 url 语法自动加载文档片段:
注意jsp页面和ID选择器之间的空白,保留它很重要,否则它将无法工作。
I see now what is the problem.
Unfortunately, using an url
dialog_applet.jsp#dialog-modal-district
will load completely the content of the jsp page, not only the fragment you specify.You have two options to achieve what you want.
Extract yourself the actual content you want to insert into the dialogs. The ajax request will load the full jsp page, using the .find() method you can select the part that interests you and only append it to your dialog:
Use the .load() method from jQuery. Its role is to load content from the specified url and it allows to load document fragments automatically by using a url syntax a little like the one you tried to use:
Note the white-space between the jsp page and the ID selector, this is important to keep it, otherwise it won't work.