javascript - mousedown 没有调用我的函数

标签 javascript html jquery

我已经创建了过渡链接,但是当应该使用 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/

相关文章:

javascript - Twitter-Bootstrap Modal 无法正常工作

javascript - 如何从元素的底部到顶部更改滚动条位置?

javascript - "/users/#something here"的 window.location.pathname

javascript - rails : Using Jquery for Text_Area character count

javascript - 删除表情符号但不删除非英文字符

javascript - 什么 VsCode 主题可以在 html 属性上启用漂亮的手写字体?

javascript - "undefined"不是 list 数组上设置监听器的函数

javascript - 如何使用 Javascript 提供实时 Flash 视频流的 1 分钟预览?

javascript - 实现本地存储

html - 自动等于表格的大小