我正在使用.net 2.0。我有两个图像都与一个相关的图像有关。他们的工作方式与艾滋病一样有效。发生的事情是我有一个列表,列表中有一个图像。当我点击第一个列表按钮时,第一个列表显示,第二个列表隐藏,同时第二个列表上的按钮需要更改。但第二个列表上的按钮不会改变。第一个列表上的按钮工作正常,只有当我点击任何一个按钮时,secon列表上的按钮始终保持不变。
当我想设置按钮的src以更改单击哪个按钮时,问题就出现了。这是vb.net中的代码1和javascript。
Dim divUserPageMediaUrlChooser As New Div
divInnerContainer.Controls.Add(divUserPageMediaUrlChooser)
divUserPageMediaUrlChooser.CSSClass = "divuserpagemediachooseurlyoutube"
Dim imageYoutubeUrlChooser As New Image
divUserPageMediaUrlChooser.Controls.Add(imageYoutubeUrlChooser)
imageYoutubeUrlChooser.CssClass = "imageupselectormedia"
imageYoutubeUrlChooser.ImageUrl = "images/userhomepage/upselector.png"
Dim divUserPageMediaUrlChooserText As New Div
divUserPageMediaUrlChooser.Controls.Add(divUserPageMediaUrlChooserText)
divUserPageMediaUrlChooserText.CSSClass = "divuserpagemediachooseurlyoutubetext"
divUserPageMediaUrlChooserText.InnerText = "Upload media via URL"
Dim divYoutbeMediaSelectorContainer1 As New Div
divInnerContainer.Controls.Add(divYoutbeMediaSelectorContainer1)
divYoutbeMediaSelectorContainer1.CSSClass = "divyoutubemediaselectorcontainer1"
Dim divUserPageMediaYoutubeChooserSeperator As New Div
divInnerContainer.Controls.Add(divUserPageMediaYoutubeChooserSeperator)
divUserPageMediaYoutubeChooserSeperator.CSSClass = "divuserpagemediachooseyoutubesperator"
Dim divUserPageMediaUrlChooser2 As New Div
divInnerContainer.Controls.Add(divUserPageMediaUrlChooser2)
divUserPageMediaUrlChooser2.CSSClass = "divuserpagemediachooseurlyoutube"
Dim imageYoutubeUrlChooser2 As New Image
divUserPageMediaUrlChooser2.Controls.Add(imageYoutubeUrlChooser2)
imageYoutubeUrlChooser2.CssClass = "imageupselectormedia"
imageYoutubeUrlChooser2.ImageUrl = "images/userhomepage/downselector.png"
Dim divUserPageMediaSearchChooserText As New Div
divUserPageMediaUrlChooser2.Controls.Add(divUserPageMediaSearchChooserText)
divUserPageMediaSearchChooserText.CSSClass = "divuserpagemediachooseurlyoutubetext"
divUserPageMediaSearchChooserText.InnerText = "Upload media via searching Youtube"
Dim divYoutbeMediaSelectorContainer2 As New Div
divInnerContainer.Controls.Add(divYoutbeMediaSelectorContainer2)
divYoutbeMediaSelectorContainer2.CSSClass = "divyoutubemediaselectorcontainer2"
imageYoutubeUrlChooser.Attributes.Add("onmousedown", String.Format("SelectYoutubeChoose('{0}','{1}','{2}','{3}','{4}')", imageYoutubeUrlChooser.ClientID, divYoutbeMediaSelectorContainer1.ClientID, divYoutbeMediaSelectorContainer2.ClientID, imageYoutubeUrlChooser.ClientID, imageYoutubeUrlChooser2.ClientID))
imageYoutubeUrlChooser2.Attributes.Add("onmousedown", String.Format("SelectYoutubeChoose('{0}','{1}','{2}','{3}','{4}')", imageYoutubeUrlChooser2.ClientID, divYoutbeMediaSelectorContainer1.ClientID, divYoutbeMediaSelectorContainer2.ClientID, imageYoutubeUrlChooser.ClientID, imageYoutubeUrlChooser2.ClientID))
的Javascript
function SelectYoutubeChoose(theId, id1, id2, imageId1, imageId2) {
var theImage = $("#" + theId);
var container1 = $("#" + id1);
var container2 = $("#" + id2);
var image1 = $("#" + imageId1);
var image2 = $("#" + imageId2);
if (theImage.attr("id") == image2.attr("id"))
{
if ($(container2).css("display") == "block") {
$(container1).show();
$(container2).hide();
$(image2).attr("src", "images/userhomepage/upselector.png");
$(image1).attr("src", "images/userhomepage/downselector.png");
// document.getElementById(imageId2).src = "images/userhomepage/upselector.png";
// document.getElementById(imageId1).src = "images/userhomepage/downselector.png";
}
else {
$(container1).hide();
$(container2).show();
$(image2).attr("src", "images/userhomepage/downselector.png");
$(image1).attr("src", "images/userhomepage/upselector.png");
}
}
if (theImage.attr("id") == image1.attr("id")) {
if ($(container1).css("display") == "block") {
$(container1).hide();
$(container2).show();
$(image2).attr("src", "images/userhomepage/downselector.png");
$(image1).attr("src", "images/userhomepage/upselector.png");
}
else {
$(container1).show();
$(container2).hide();
$(image2).attr("src", "images/userhomepage/upselector.png");
$(image1).attr("src", "images/userhomepage/downselector.png");
}
}
}
答案 0 :(得分:3)
您可能希望考虑使用CSS背景并简单地交换类名。更干净。