[英]li onclick function not getting called
I have trouble calling the onclick function inside the li element.when I put a url to the href it works fine. 我在li元素内调用onclick函数时遇到麻烦。当我将URL放入href时,它可以正常工作。 But I want to call a javascript function through onclick .Any help is appreciated.
但我想通过onclick调用javascript函数。感谢您的帮助。
function display_s(){ alert("success"); }
<div style="" class="icon_bar"> <ul style="padding:0 ; margin : 0;display:flex; justify-content: center;"> <li onclick="display_specs()"> <a href="#" > <div style="display:flex;align-items:center;flex-direction:column"> <div style="height:35px;width:35px;padding:5px"> <img src="/static/phone.bmp" style="max-width:100%;height:auto"></div> <div style="padding:5px" > Mobile</div> </div> </a> </li> </ul> </div>
Change to what I type. 更改为我输入的内容。 You have some type error.
您遇到一些类型错误。
function display_specs(){ alert("success"); }
<div style="" class="icon_bar"> <ul style="padding:0 ; margin : 0;display:flex; justify-content: center;"> <li onclick="display_specs()"> <a href="#" > <div style="display:flex;align-items:center;flex-direction:column"> <div style="height:35px;width:35px;padding:5px"> <img src="/static/phone.bmp" style="max-width:100%;height:auto"></div> <div style="padding:5px" > Mobile</div> </div> </a> </li> </ul> </div>
You're onclickfucntion name and in script
tag name must be same like that. 您的onclickfucntion名称和
script
标签名称必须相同。 Also if you wanna learn more information about onClick
you can check this link 另外,如果您想了解有关
onClick
更多信息,则可以检查此链接
function display_specs(){ alert("success"); }
<div style="" class="icon_bar"> <ul style="padding:0 ; margin : 0;display:flex; justify-content: center;"> <li onclick="display_specs()"> <a href="#" > <div style="display:flex;align-items:center;flex-direction:column"> <div style="height:35px;width:35px;padding:5px"> <img src="/static/phone.bmp" style="max-width:100%;height:auto"></div> <div style="padding:5px" > Mobile</div> </div> </a> </li> </ul> </div>
Call the function in li and it will work.
<script>
function display_s()
{
alert('check');return false;
}
</script>
</head>
<body>
<div style="" class="icon_bar">
<ul style="padding:0 ; margin : 0;display:flex; justify-content: center;">
<li onclick="display_s()" style="cursor:pointer"></li>
</ul>
</div>
</body>
You are calling to the wrong function which is not defined.
您正在调用错误的未定义函数。 when you are click on
li
you should call to the functiondisplay_s()
.当您单击
li
,应该调用函数display_s()
。
function display_s(){ alert("success"); }
<div style="" class="icon_bar"> <ul style="padding:0 ; margin : 0;display:flex; justify-content: center;"> <li onclick="display_s()"> <a href="#" > <div style="display:flex;align-items:center;flex-direction:column"> <div style="height:35px;width:35px;padding:5px"> <img src="/static/phone.bmp" style="max-width:100%;height:auto"></div> <div style="padding:5px" > Mobile</div> </div> </a> </li> </ul> </div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.