我可以到以下.htm文件複製到我的索尼愛立信C510和鼠標懸停工作:爲什麼JavaScript可以在我的索尼愛立信C510瀏覽器上工作,但不是JavaScript + jQuery?
<script type="text/javascript">
<!--
if (document.images) {
front = new Image
back = new Image
front.src = "front.png"
back.src = "back.png"
}
function swapImage(thisImage,newImage) {
if (document.images) {
document[thisImage].src = eval(newImage + ".src")
}
}
-->
</script>
<img onMouseOver="swapImage('test','back')"
onMouseOut="swapImage('test','front')"
src="front.png"
border="0"
name="test">
但我不能得到任何jQuery的工作,例如,當我點擊鏈接時,以下示例沒有響應。我知道jquery-1.4.2.min.js
文件在正確的地方存在,因爲我複製目錄中的所有文件:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript" src="javascript/jquery-1.4.2.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$("div > div.question").click(function() {
if($(this).next().is(':hidden')) {
$(this).next().show();
} else {
$(this).next().hide();
}
});
});
</script>
<style>
div.flashcard {
margin: 0 10px 10px 0;
}
div.flashcard div.question {
background-color:#ddd;
width: 400px;
padding: 5px;
cursor: hand;
cursor: pointer;
}
div.flashcard div.answer {
background-color:#eee;
width: 400px;
padding: 5px;
display: none;
}
</style>
</head>
<body>
<div id="1" class="flashcard">
<div class="question">Who was Wagner?</div>
<div class="answer">German composer, conductor, theatre director and essayist, primarily known for his operas (or "music dramas", as they were later called). Unlike most other opera composers, Wagner wrote both the music and libretto for every one of his works.</div>
</div>
<div id="2" class="flashcard">
<div class="question">Who was Thalberg?</div>
<div class="answer">a composer and one of the most distinguished virtuoso pianists of the 19th century.</div>
</div>
</body>
</html>
我怎樣才能獲得的jQuery在我的索尼愛立信C510的瀏覽器工作,因爲普通的JavaScript呢?
補充:
基於rchern的建議下,我嘗試這樣做:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript" src="javascript/jquery-1.4.2.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('#test').css("background-color","lightgreen");
alert("hi from jQuery");
});
</script>
</head>
<body>
<p>test from html</p>
<p id="test">jquery should turn this green</p>
</body>
</html>
在Firefox在桌面上顯示彈出式窗口,變成線綠色,但手機上的jQuery似乎沒有效果,只顯示文字。
您是否在桌面瀏覽器中嘗試過它,以驗證它在那裏有效?你試過只是做$(document).ready(function(){alert(「hi from jQuery」);}); – 2010-07-06 23:23:58
它在Firefox中工作,我會嘗試其他。 – 2010-07-06 23:24:56
低端設備沒有jQuery所需的全部JavaScript支持。其中一些HTML/CSS也不完全支持。 – Marko 2010-07-06 23:30:22