简体   繁体   English

如何在点击时重定向到li

[英]How to redirect to li on click

How can I show li on click of a button? 单击按钮如何显示li? I want on click of assignment button, Assign Lab Room & Technican li should open. 我要单击“分配”按钮,应打开“分配实验室室和技术人员”。

Below is my html code for it. 下面是我的html代码。

<div class="box-header" id = "liid">
    <ul class="nav nav-tabs pull-left" style="cursor: move;">
        <li ><a href="#payment" data-toggle="tab">Application</a></li>
        <li class="active"  id="assigned"><a href="#appointment" data-toggle="tab">Assign Lab Room & Technican</a></li>                                 
        <li class=""><a href="#analysis" data-toggle="tab">Technican Analysis</a></li>
        <ng-container *ngIf="usertypeid==='3'">
        <li class=""><a href="#audit" data-toggle="tab">Audit1</a></li>
        <li class=""><a href="#audit1" data-toggle="tab">Audit2</a></li>
        </ng-container>
    </ul>
</div>  

<button type="button" class="btn btn-primary btn-xs" data-toggle="modal" (click)="show()" ><i class="fa fa-edit"></i>&nbsp;Assignment</button>

Below is my jQuery function as well: 以下也是我的jQuery函数:

show(){
    console.log("afdghj");
    $( "#assigned").show();            
}

If I understood correctly, you are trying to simulate the click on your <li> when clicking on your button. 如果我理解正确,则您正在尝试模拟单击按钮时<li>上的单击。 This is not the appropiate answer if you want to redirect to your #appointment path, because the href="#appointment" is set in your <a> tag and not in your <li> . 如果要重定向到#appointment路径,这不是适当的答案,因为href="#appointment"是在<a>标记中设置的,而不是在<li>

Saying that, what I think you should do is to make your button really do what you want, and redirect to the path you want in its action. 话虽如此,我认为您应该做的是使您的按钮真正实现您想要的功能,并重定向到您希望其执行操作的路径。

Then, your code must be 然后,您的代码必须是

 function show(){ console.log("afdghj"); window.location.href= '#appointment'; }; 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class="box-header" id = "liid"> <ul class="nav nav-tabs pull-left" style="cursor: move;"> <li ><a href="#payment" data-toggle="tab">Application</a></li> <li class="active" id="assigned"><a href="#appointment" data-toggle="tab">Assign Lab Room & Technican</a></li> <li class=""><a href="#analysis" data-toggle="tab">Technican Analysis</a></li> <ng-container *ngIf="usertypeid==='3'"> <li class=""><a href="#audit" data-toggle="tab">Audit1</a></li> <li class=""><a href="#audit1" data-toggle="tab">Audit2</a></li> </ng-container> </ul> </div> <button type="button" class="btn btn-primary btn-xs" data-toggle="modal" onclick="show()" ><i class="fa fa-edit"></i>&nbsp;Assignment</button> 

In jQuery show() event means to remove style display: none and hide() does the opposite. 在jQuery中, show()事件意味着删除样式display: nonehide()则相反。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM