gpt4 book ai didi

javascript - MVC 3 中带有 jQ​​uery 的低调 JavaScript

转载 作者:行者123 更新时间:2023-11-29 15:48:49 25 4
gpt4 key购买 nike

假设在我拥有的 MVC 3 应用程序中的某处

if (Model.ImageListGallery != null)
{
<h3>@ImagesTranslation.Gallery</h3>

foreach (var imageInGallery in Model.ImageListGallery)
{
<div id="@imageInGallery.IdImage">
<a rel="group" href= "@Url.Action("displaybig", "news", new { idNews = Model.IdNews, idImage = imageInGallery.IdImage })">
<img src= "@Url.Action("displaysmall", "news", new { idNews = Model.IdNews, idImage = imageInGallery.IdImage })" alt=""/></a>
@Html.Label(ImagesTranslation.Description)
@Html.TextArea("Description", imageInGallery.Description, new { id = "area" + imageInGallery.IdImage, onfocus = "removeDisabledBtnOnImage('" + imageInGallery.IdImage + "')" })
<button disabled="disabled" id="btn@(imageInGallery.IdImage)" onclick="saveDescription('@imageInGallery.IdImage')">@CommonTranslations.Save</button>
<img class="@imageInGallery.IdImage" src="@Href("~/Content/delete.png")" onclick="deleteImage('@imageInGallery.IdImage')" title="@ImagesTranslation.DeleteImage" alt=""/>
</div>
}
}

在那种情况下(事件 onfocus 和 onclick?),您将如何使用不引人注目的 JavaScript 和 jQuery?

最佳答案

通过向父 div 添加一个类,您可以将每个画廊图像识别为需要将处理程序添加到其元素的东西:

foreach (var imageInGallery in Model.ImageListGallery)
{
<div id="@imageInGallery.IdImage" class="gallery-image">
<a rel="group" href= "@Url.Action(...)">
<img src= "@Url.Action(..." alt=""/></a>
@Html.Label(ImagesTranslation.Description)
@Html.TextArea("Description", imageInGallery.Description, new { id = "area" + imageInGallery.IdImage })
<button disabled="disabled" id="btn@(imageInGallery.IdImage)">@CommonTranslations.Save</button>
<img class="@imageInGallery.IdImage" src="@Href("~/Content/delete.png")" title="@ImagesTranslation.DeleteImage" alt=""/>
</div>
}
$(function() {
$('.gallery-image').each(function() {
var t = $(this);
var imageId = t.attr('id');
t.find('textarea').onfocus(function() {
removeDisabledBtnOnImage(imageId);
});
t.find('btn').onclick(function(){
saveDescription(imageId);
});
t.find('img').onclick(function(){
deleteImage(imageId);
});
});
});

还有其他方法可以解决这个问题,但希望这能让您大致了解。

关于javascript - MVC 3 中带有 jQ​​uery 的低调 JavaScript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8183776/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com