问题描述
我读过的每个站点都说,如果声明了一个函数,它将只带有一个参数,但是我不能在这里使用它.
Every site I've read says a function would just take a parameter if you declare it, however I can't get it to work here.
像这样工作:
<script type='text/javascript'>
function trackSubmit() {
setTimeout(function(){
ga('send', 'event', 'category', 'action', 'link', 4);
}, 100);
}
</script>
并且:
<form onsubmit="trackSubmit()">
但是,如果我尝试这样的操作,它将无法正常工作.
However, if I try something like this, it doesn't work.
<script type='text/javascript'>
function trackSubmit(category, action, link) {
setTimeout(function(){
ga('send', 'event', category, action, link, 4);
}, 100);
}
</script>
<form onsubmit="trackSubmit(testcategory, testaction, testlink)">
我该怎么做才能解决此问题?还是应该只具有多个功能,例如trackSubmit1,trackSubmit2等?虽然那不是很方便.
What can I do to fix this? Or should I just have multiple functions like trackSubmit1, trackSubmit2, etc? Though that wouldn't be very convenient.
谢谢您的帮助.
推荐答案
您需要使用qoutation<form onsubmit="trackSubmit('testcategory', 'testaction', 'testlink')">
如果有变量,则需要像\''+ testcategory +'\'那样串联...
you need to use qoutation<form onsubmit="trackSubmit('testcategory', 'testaction', 'testlink')">
if there are variable then need to concatenate like \''+testcategory+'\' , ...
这篇关于JavaScript函数参数不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!