javascript - 我不能在我的代码中使用函数参数
问题描述
我的 JavaScript 代码是
$(document).ready(function today(tony){
var mytext = tony;
$('#tod').click(function(event){
event.preventDefault();
$.ajax({
url:"/ajaxdemo",
data:{text:mytext},
method:"POST",
success: function(res){
alert(res.from)
},
error: function(err){
console.log(err)
}
})
}) })
我的html代码是
<a id="tod" href="" onclick="today(tony)" ><i class="fa fa-calendar"></i>{{this.tod}}</a>
我不能接受名为 today(tony) 的函数中的参数
解决方案
我得到了解决方案
将javascript代码更改为
function today(tod) {
$.ajax({
url: "/ajaxdemo",
data: {
text: tod
},
method: "POST",
success: function (res) {
alert(res.from)
},
error: function (err) {
console.log(err)
}
});
return false;
}
将 HTML 代码更改为
<a id="tod" href="" onclick="today(tony)" ><i class="fa fa-calendar"></i>{{this.tod}}</a>
推荐阅读
- xml - 如何在 PhpStorm 中启动和编写 .xml 页面
- python - Python:将元组列表转换为字典
- c++ - 由类析构函数完成的同步
- amazon-web-services - 向 API 网关添加 IP 白名单安全性
- node.js - Node.js - 限制我发出的请求数量
- python - 我无法安装 django-constance,错误为找不到满足 django-constance 要求的版本(来自版本:)
- python - Docker 容器填满了我的磁盘
- java - 无法为奥利奥通知启用闪烁灯并禁用通知声音
- mysql - SyntaxError: Missing ) 在 Mysql 查询中的参数列表之后
- xaml - 将值从内部样式绑定到其外部样式