我已經創建了轉換的鏈接,但應該使用onmousedown事件調用函數我得到一個未捕獲的未定義的函數。很明顯,我的功能是定義的。我仍然在學習代碼,所以我沒有看到或理解它。任何提示將不勝感激。mousedown不叫我的功能
<html>
<head>
<script type="text/javascript"src="js/jquery.js"></script>
<script type="text/javascript" src="js/jquery-ui.js"></script>
<script type="javascript">
$(document).ready(function(){
var url = "phpajaxtut.php";
});
function swapContent(cv){
$("#myDiv").html("animated gif goes here").show();
.post(url, {contentVar:cv}, function(data){
$("#myDiv").html(data).show();
});
}
</script>
<a href="#" onClick="return false" onmousedown="swapContent('con1')">Click the text</a>
<a href="#" onClick="return false" onmousedown="swapContent('con2');">Click the text</a>
<a href="#" onClick="return false" onmousedown="swapContent('con3');">Click the text</a>
</head>
<body >
<div id ="myDiv">My default content</div>
</body>
</html>
'.post'是一個語法錯誤。你是不是指'$ .post'?另外,你的'url'變量超出了'swapContent'函數的範圍。 –