I have structure like each image has input below. I have x images on the screen. Each of image has onlick option
onclick="imageClicked(this)"
Function creates border to image and show collapsed input. Image`s border is showing but input is not beign visible.
Here`s the function
function imageClicked(image) {
var input = $(image).closest("input");
$(image).css('outline', "solid 2px #5bc0de");
$(input).css("visibility", "visible");
$(input).focus();
$(input).focusout(function () {
$(image).css('outline', "0");
if ($(input).val() === "0") {
$(input).css("visibility", "collapse");
}
});
$(image).focusout(function () {
if ($(input).val() === "") {
$(image).css('outline', "0");
}
});
}
Here is HTML Structure in Razor View
@for (int i = 0; i < Model.Boxes.Count; i++){
var base64 = Convert.ToBase64String(Model.Boxes[i].Photo);
var imgSrc = String.Format("data:image/gif;base64,{0}", base64);
var imageId = Model.Boxes[i].BoxId;
@Html.HiddenFor(m => m.Boxes[i].BoxId)
<div class="col-md-2">
<img src="@imgSrc" width="50%" alt="@Model.Boxes[i].Name" id="@string.Format("image{0}", imageId)" onclick="imageClicked(this)" />
@Html.TextBoxFor(m => m.Boxes[i].Quantity, new { @class = "form-control", @style = "visibility: collapse; width: 50%; margin-top: 1%", @id = string.Format("input{0}", imageId) })
</div>
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…