有點難倒了這個,所以我希望你們可以幫忙。使用jQuery設置事件回調中的元素值
看起來我可能已經找到了IE相關的jQuery bug。創建了一個小測試(包括在這裏),我可以解決這個問題。在Firefox和Chrome中運行良好,並且在IE8-9中失敗。
問題是DIV「podcastStatus」未在更新發生在事件回調中的正確時刻更新。您可以使用IE工具和Firebug在本地進行測試,並在代碼中評論我設置的斷點。
步驟:
- 在Firebug中設置斷點和IE 根據我的代碼
- 點擊或者「下一步」或「上一頁」在DIV
- 文本註釋
- 開發工具應根據您點擊哪個按鈕更改爲「下一步」或「上一步」
- DIV中的文本然後應恢復爲「播放...」
我認爲這是innerHTML相關的,但我已經嘗試了innerHTML DIV包裝技巧和無骰子。
注:我已經使用.text()和.html()沒有解析。
這裏的測試用例:
<body>
<style type="text/css">
#podcastStatus {
background-color: ButtonHighlight;
font-size: 120pt;
font-weight: bolder;
color: Black;
margin: 0 auto;
text-align: center;
position:absolute; top:0; bottom:0; left:0; right:0;
margin:auto; height:200px; width:100%;
z-index: 100;
}
</style>
<div id="podcastStatus">Playing...</div>
<div id="targetBtns">
<input type="button" name="prev" id="prev" value="Prev"/>
<input type="button" name="next" id="next" value="Next"/>
</div>
<script>
function onButtonClicked(e) {
switch (e.target.defaultValue) {
case "Next":
// Use IE tools or Firebug...
//Set breakpoint here. Immediate after this executes, DIV text should be updated to "Prev"....
$('#podcastStatus').html("Prev").show();
break;
case "Prev":
// Use IE tools or Firebug...
//Set breakpoint here. Immediate after this executes, DIV text should be updated to "Next"....
$('#podcastStatus').html("Next").show();
break;
}
//Set breakpoint here. DIV should show either "Prev" or "Next" at this point...
playPause();
}
function playPause() {
$('#podcastStatus').text("Playing...").fadeIn('slow');
}
$("#targetBtns").click(function(event) { onButtonClicked(event) });
</script>
</body>
哇,我甚至沒有注意到在第一次提問是誰 - 嗨雷伊!今晚有一杯好水? ;) – JAAulde 2011-04-06 04:08:19
呵呵。你好,吉姆。:) – 2011-04-07 12:41:05