简体   繁体   English

在页面加载时使链接处于活动状态,并使其保持活动状态,直到单击另一个指定的按钮为止

[英]make link active when page loads and force it ot remain active untill another specified button is clicked

I would like to make one link active when the page loads and make it remain active untill some specified button is pressed. 我想在页面加载时使一个链接处于活动状态,并使其保持活动状态,直到按下某些指定的按钮为止。 For example I have two buttons A and B, then when Page load, BUtton A will remain active and not untill Button B is clicked it will remain active. 例如,我有两个按钮A和B,那么当页面加载时,按钮A将保持活动状态,直到单击按钮B才保持活动状态。 ( alternatively, I would like to get .focus style in one of there button as user loads the page for first time. ps I am using both button inside Accordin. (或者,我希望在用户第一次加载页面时在其中一个按钮中获得.focus样式。ps我在Accordin中使用了两个按钮。

Here is the html file. 这是html文件。

<a   href="SECA.html" style="  z-index:0; color: white; "     
target="targetframe"  class="myButton" >Section A </a>


<a   href="SECB.html" style="margin-left: 1%; z-index:0 color: white; "   
target="targetframe"  class="myButton" >Section B </a>

and style file is 和样式文件是

.myButton {
-moz-box-shadow:inset 0px 1px 0px 0px #f5978e;
-webkit-box-shadow:inset 0px 1px 0px 0px #f5978e;
box-shadow:inset 0px 1px 0px 0px #f5978e;
background:-webkit-gradient(linear, left top, left bottom, color-stop(0.05,  
#f24537), color-stop(1, #c62d1f));
background:-moz-linear-gradient(top, #f24537 5%, #c62d1f 100%);
background:-webkit-linear-gradient(top, #f24537 5%, #c62d1f 100%);
background:-o-linear-gradient(top, #f24537 5%, #c62d1f 100%);
background:-ms-linear-gradient(top, #f24537 5%, #c62d1f 100%);
background:linear-gradient(to bottom, #f24537 5%, #c62d1f 100%);
filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#f24537', 
endColorstr='#c62d1f',GradientType=0);
background-color:#f24537;
-moz-border-radius:6px;
-webkit-border-radius:6px;
border-radius:6px;
border:1px solid #d02718;
display:inline-block;
cursor:pointer;
color:#ffffff;
font-family:Arial;
font-size:13px;
font-weight:bold;

padding: 6.5px 13px;
text-decoration:none;
text-shadow:0px 1px 0px #810e05;

}
.myButton:focus {
-moz-box-shadow:inset 0px 1px 0px 0px #bbdaf7;
-webkit-box-shadow:inset 0px 1px 0px 0px #bbdaf7;
 box-shadow:inset 0px 1px 0px 0px #bbdaf7;
 background:-webkit-gradient(linear, left top, left bottom, color-
 stop(0.05, #79bbff), color-stop(1, #378de5));
 background:-moz-linear-gradient(top, #79bbff 5%, #378de5 100%);
 background:-webkit-linear-gradient(top, #79bbff 5%, #378de5 100%);
 background:-o-linear-gradient(top, #79bbff 5%, #378de5 100%);
 background:-ms-linear-gradient(top, #79bbff 5%, #378de5 100%);
 background:linear-gradient(to bottom, #79bbff 5%, #378de5 100%);
 filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#79bbff', 
endColorstr='#378de5',GradientType=0);
background-color:#79bbff;
-moz-border-radius:6px;
-webkit-border-radius:6px;
 border-radius:6px;
border:1px solid #84bbf3;
display:inline-block;
cursor:pointer;
color:#ffffff;
font-family:Arial;
font-size:13px;
font-weight:bold;
padding:6.5px 13px;
text-decoration:none;
text-shadow:0px 1px 0px #528ecc;
 }

You could use jQuery event handlers to accomplish this. 您可以使用jQuery事件处理程序来完成此操作。 Both the buttons are active by default on page load. 默认情况下,这两个按钮在页面加载时均处于活动状态。

You could have ids on the buttons to make it easier to register the onclick handler. 您可以在按钮上添加ID,以便更轻松地注册onclick处理程序。

Eg : 例如:

<a id="secA" href="SECA.html" style="z-index:0; color: white;" target="targetframe"  class="myButton"> Section A </a>
<a id="secB" href="SECB.html" style="margin-left: 1%; z-index:0 color: white;" target="targetframe" class="myButton"> Section B </a>

<script>
    $(function() {
        $("#secB").on("click", function() {
            $("#secA").prop("disabled", true); //jQuery 1.6+
            //$("#secA").attr("disabled", "disabled") //jQuery 1.5 and below
        });
    });
</script>

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

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