bra*_*rad 4 html javascript vb.net asp.net jquery
当用户将鼠标移过时,我正在通过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>
Run Code Online (Sandbox Code Playgroud)
使用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);
});
Run Code Online (Sandbox Code Playgroud)
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
Run Code Online (Sandbox Code Playgroud)
服务器对此类控件的客户端更改一无所知.可能您必须在隐藏字段或隐藏文本框中存储已由javascript更改的值,然后在服务器端收集此值.
希望这可以帮助
编辑:
如果你只想获得var n的值,你可以这样做:
// aspx;
<asp:HiddenField ID="HidScore" runat="server" />
Run Code Online (Sandbox Code Playgroud)
/// javascript
$(document).on("mouseover", "input.stars", function () {
var hid=$("#<%= HidScore.ClientID %>");
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);
hid.val(n);
});
Run Code Online (Sandbox Code Playgroud)
然后在vb.net中获取值:HidScore.value
客户端对服务器端控件的更改通常将不保留或发布回服务器。
考虑创建一个隐藏的字段<asp:HiddenField />
控件,并让您的JavaScript也更新该值。HiddenFields
/ <input type="hidden" />
将通过PostBack返回到服务器。然后,您的代码将需要检查的HiddenField
可能更改或更新,并将这些更改路由回ImageButton
ImageUrl
属性。
归档时间: |
|
查看次数: |
5464 次 |
最近记录: |