我已经创建了过渡链接,但是当应该使用 onmousedown 事件调用该函数时,我得到了一个未捕获的未定义函数。显然我的功能已定义。我还在学习代码,所以我看不到或不明白它是什么。任何提示将不胜感激。
<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>
最佳答案
既然您已经在使用 jQuery,为什么不直接使用 $.click();
而放弃超链接呢?如果您想要的话,您可以轻松地设置一些 span 的样式,使其看起来像 a
。我的示例只是更新了一些文本,但您可以在其中放置/调用您的函数。
参见 here :
// html
<span>Click Me</span>
<br />
<span>Click Me</span>
// js
var n = 0;
$("span").click(function(){
$(this).text($(this).text() + " " + n++);
});
关于javascript - mousedown 没有调用我的函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12484694/