我的 jquery 代码有什么问题?
我在下面给出了我的代码,
$(function() {
$("get-reservation-id").click(function() {
$(this).load("<%=Url.Action("GetReservation", "ModalPopup") %>",
function() {
$("<div>").dialogr({
autoOpen: false,
width: 700,
title: 'Car Rental Application',
modal: true,
overlay: {
opacity: 0.5,
background: "black"
}
});
});
});
});
此代码不会生成弹出的 jquery ui 对话框。
get-reservation-id:是给放置在锚标记内的图像
GetReservation:是部分视图
ModalPopop:是名称控制器的(我有一个返回 GetReservation 视图的操作)
任何想法为什么这不起作用。另一方面,我编写了一些有效的代码。请参阅下面的
工作代码:
$("#vehicle-search-id").click(function() {
$("#vehicle-search-id").load("/ModalPopup/VehicleSearch",
function() {
$("#vehicle-search").dialogr({
width: 700,
modal: false,
title: 'Car Rental Application'
});
});
});
我选择不使用它的原因是因为我想使用 <%=Url.Action("GetReservation", "ModalPopup") %>
而不是 >/ModalPopup/VehicleSearch
并希望使用比 $("#vehicle-search") 更常见的
$("
").dialogr({
)。 dialogr({
非常感谢
我的目标
我想使用 Jquery 对话框创建一个弹出窗口并放置一个 其中的部分视图。
I have given my code below,
$(function() {
$("get-reservation-id").click(function() {
$(this).load("<%=Url.Action("GetReservation", "ModalPopup") %>",
function() {
$("<div>").dialogr({
autoOpen: false,
width: 700,
title: 'Car Rental Application',
modal: true,
overlay: {
opacity: 0.5,
background: "black"
}
});
});
});
});
This code does not produce a jquery ui dialog pop up.
get-reservation-id : is the is given to an image placed within an anchor tag
GetReservation : is the partial view
ModalPopop : is the name of the controller(Where I have an action that returns GetReservation View)
Any Idea Why this does not work. On the other hand I Have written some code which does work. See Below
Working code:
$("#vehicle-search-id").click(function() {
$("#vehicle-search-id").load("/ModalPopup/VehicleSearch",
function() {
$("#vehicle-search").dialogr({
width: 700,
modal: false,
title: 'Car Rental Application'
});
});
});
The reason why I chose to not use this is because I wanted to use <%=Url.Action("GetReservation", "ModalPopup") %>
instead of /ModalPopup/VehicleSearch
and wanted to use a more common $("<div>").dialogr({
than $("#vehicle-search").dialogr({
Many Thanks
My Aim
I want to create a pop up using a Jquery dialog and put a
partial view in it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我注意到您在第一个示例中将 autoOpen 选项设置为 false 。因此,您问题中的第一个代码片段将创建一个 jQuery 对话框,但不会打开它。我建议将 autoOpen 设置为 true(默认值)或包含一行代码以在其他位置打开对话框。
I've noticed you've got the autoOpen option set to false in your first example. So the first code snippet in your question would create a jQuery dialog, but won't open it. I would suggest either setting autoOpen to true (which is default) or including a line of code to open the dialog elsewhere.
您的 jQuery 选择器格式错误。使用
$("#get-reservation-id")
选择具有该 id 的元素,使用$("div")
选择所有div标签。
我还怀疑您不想选择第 5 行中的所有
div
,但我不知道您想要选择什么,所以不能真正选择提出任何建议。我建议您查看 jQuery 选择器 文档。编辑:我想我明白你在做什么。您正在从
Url.Action("GetReservation", "ModalPopup")
获取 HTML 响应,并希望显示一个模式对话框,其中的内容取自(可能只是)div
在该回应中。在这种情况下,您确实需要在第 5 行上使用
$("div")
。请记住,jQuery 选择器的工作方式与 CSS 选择器类似 -$('div')
选择所有 < code>div 元素,$('#foo')
选择 id 为“foo”的元素,$('.bar')
选择所有元素有一类“bar”。Your jQuery selectors are of the wrong form. Use
$("#get-reservation-id")
to select the element with that id, and$("div")
to select alldiv
tags.I also suspect you don't want to select all
div
s in your 5th line, but I don't know what you do want to select, so can't really make any suggestions. I suggest you have a look at the jQuery Selectors documentation.Edit: I think I see what you're doing. You're grabbing the HTML response from
Url.Action("GetReservation", "ModalPopup")
and want to display a modal dialog with contents taken from the (presumably only)div
in that response.In that case, you do want
$("div")
on your line 5. Remember that jQuery selectors work like CSS selectors -$('div')
selects alldiv
elements,$('#foo')
selects the element with id "foo", and$('.bar')
selects all elements with a class of "bar".这是更正后的代码
Here is the rectified code
我想你想要这个:
I think you want this: