href调用相同的Javascript函数...如何在href onclick上调用不同的函数? [英] href calling the same Javascript function... how to call different functions on href onclick?
问题描述
我是Javascript世界的新手。在我的项目编码中,我有5个Javascript函数和5个href。每当我点击href,那么应该调用它各自的Javascript函数(它将从页面后面的代码调用相应的方法)。但是当我点击任何href链接时,它会调用最后一个Javascript函数(即函数5th())。
我在下面提到了我的编码:
< script type = text / javascript >
function first(){
functionaCall = ' <%= fill(first)%>';
}
function second(){
functionaCall = ' < span class =code-string><%= fill(second)%>';
} function third(){
functionaCall = ' <%= fill(third)%>';
}
function 第四(){
functionaCall = ' < span class =code-string><%= fill(fourth)%>';
}
function fifth(){
functionaCall = ' < span class =code-string><%= fill(Fifth)%>';
}
< / 脚本 >
。
。
。
。
。
< ul >
< li > < a href = # id = 首先 önclick = first(); > 1 < / a > < / li >
< li > < a href = # id = second önclick = second(); > 2 < / a > 跨度> < span class =code-keyword>< / li >
< li > < a href = # id = third önclick = third(); > 3 < / a > < / li >
< li > < a href = # id = 第四个 önclick = 第四(); > 4 < / a > < /锂跨度> >
< li > < a < span class =code-attribute> href = # id = 第五个 önclick = 第五(); > 5 < / a > < / li >
< / ul >
请告诉我如何根据点击的href调用Javascript函数。
(即点击href-1时,然后它应该调用函数first()...类似于所有href点击的)
在此先感谢:)
祝你有美好的一天:)
为什么你不把Id放到你的href?
< ul>< li>< a id =Fivehref =#önclick=fifth();> 5< / a>< / li>< / ul>
Hi, I am new to Javascript world. In my project codings i have 5 Javascript functions and 5 href's. whenever i click the href, then its respective Javascript function should be called(which will invoke the respective method from code behind page). But when ever i click any href link, its calling the last Javascript function(i.e function fifth() here).
I have mentioned my codings below :
<script type="text/javascript">
function first() {
functionaCall = '<%= fill("first") %>';
}
function second() {
functionaCall = '<%= fill("second") %>';
}function third() {
functionaCall = '<%= fill("third") %>';
}
function fourth() {
functionaCall = '<%= fill("fourth") %>';
}
function fifth() {
functionaCall = '<%= fill("fifth") %>';
}
</script>
.
.
.
.
.
<ul>
<li ><a href="#" id="first" önclick="first();" >1</a></li>
<li><a href="#" id="second" önclick="second();">2</a></li>
<li><a href="#" id="third" önclick="third();">3</a></li>
<li><a href="#" id="fourth" önclick="fourth();">4</a></li>
<li><a href="#" id="fifth" önclick="fifth();">5</a></li>
</ul>
Please let me know how to call the Javascript functions based on the href clicked respectively.
(i.e when href-1 is clicked, then it should call function first()...similarly for all the href click's)
Thanks in Advance :)
Have a great day all :)
Why you don't put Id to your href?
<ul><li><a id="Five" href="#" önclick="fifth();">5</a></li></ul>
这篇关于href调用相同的Javascript函数...如何在href onclick上调用不同的函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!