当用户鼠标悬停时,我正在通过 Javascript 更改 ImageButtons 的 ImageUrl。在提交时,我想检查 ImageUrl 属性。但是,更改后的属性并没有反映在后面的代码中。事实上,我也在通过 javascript 更新 span 标签,它的更改值也不会反映在回发中。这些都是静态 html 元素。我没有动态创建任何这些,也没有在后面的代码中对它们进行任何操作。
HTML:
<div style="margin: 20px 0 0 0; float: left;">
<div class="divStars1" style="width: 130px; float: left;">
<input type="image" name="ctl00$MainContent$ax1" id="MainContent_ax1" class="stars" onmouseover="<code to flip image>" src="style/EmptyStar.png" style="height:20px;width:20px;" />
<input type="image" name="ctl00$MainContent$ax2" id="MainContent_ax2" class="stars" onmouseover="<code to flip image>" src="style/EmptyStar.png" style="height:20px;width:20px;" />
<input type="image" name="ctl00$MainContent$ax3" id="MainContent_ax3" class="stars" onmouseover="<code to flip image>" src="style/EmptyStar.png" style="height:20px;width:20px;" />
<input type="image" name="ctl00$MainContent$ax4" id="MainContent_ax4" class="stars" onmouseover="<code to flip image>" src="style/EmptyStar.png" style="height:20px;width:20px;" />
<input type="image" name="ctl00$MainContent$ax5" id="MainContent_ax5" class="stars" onmouseover="<code to flip image>" src="style/EmptyStar.png" style="height:20px;width:20px;" />
</div>
<div style="margin-top: 3px; width: 600px; float: left;">
<span>axs</span>
</div>
</div>
<div style="margin: 20px 0 0 0; float: left;">
<div class="divStars2" style="width: 130px; float: left;">
<input type="image" name="ctl00$MainContent$bx1" id="MainContent_bx1" class="stars" onmouseover="<code to flip image>" src="style/EmptyStar.png" style="height:20px;width:20px;" />
<input type="image" name="ctl00$MainContent$bx2" id="MainContent_bx2" class="stars" onmouseover="<code to flip image>" src="style/EmptyStar.png" style="height:20px;width:20px;" />
<input type="image" name="ctl00$MainContent$bx3" id="MainContent_bx3" class="stars" onmouseover="<code to flip image>" src="style/EmptyStar.png" style="height:20px;width:20px;" />
<input type="image" name="ctl00$MainContent$bx4" id="MainContent_bx4" class="stars" onmouseover="<code to flip image>" src="style/EmptyStar.png" style="height:20px;width:20px;" />
<input type="image" name="ctl00$MainContent$bx5" id="MainContent_bx5" class="stars" onmouseover="<code to flip image>" src="style/EmptyStar.png" style="height:20px;width:20px;" />
</div>
<div style="margin-top: 3px; width: 600px; float: left;">
<span>bx blah blah</span>
</div>
</div>
Javascript:
$(document).on("mouseover", "input.stars", function () {
var score = 0;
$("input.stars").each(function (index, element) {
// element == this
if ($(element).attr("src") == "style/FilledStar.png") {
score = score + 1;
};
});
score = score / 5;
var n = score.toFixed(2);
$("#MainContent_lblScore").text(n);
});
btnSubmit_Click 代码:
For Each ctrl As Control In Me.divSkill1.Controls
If (TypeOf ctrl Is ImageButton) Then
Dim imgCtl As ImageButton = TryCast(ctrl, ImageButton)
Dim x As String = imgCtl.ImageUrl 'HERE'S THE PROBLEM... x always equals original static value!
End If
Next