所以我有这个链接按
<a href="link" target="_blank">
<div class="well">
<span> blabla </span>
</div>
</a>
和页面中的此按钮代码
<button type="submit" class="btn-primary btn-lg" disabled="disabled"> Blabla </button>
正如您所看到的,该按钮现已停用。当我按下该链接时,如何再次启用该按钮,我该怎么做?抱歉我的英语不好..
答案 0 :(得分:6)
尝试使用toggleDisabled的广义函数
//Generalized function to make element toggleDisabled.
(function($) {
$.fn.toggleDisabled = function(){
return this.each(function(){
this.disabled = !this.disabled;
});
};
})(jQuery);
//Code to use toggleDisabled
$(document).ready(function(){
$("a").click(function(){
$("button[type='submit']").toggleDisabled();
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<a href="link" target="_blank">
<div class="well">
<span> blabla </span>
<div>
</a>
<br/>
<button type="submit" class="btn-primary btn-lg" disabled="disabled"> Blabla </button>
答案 1 :(得分:0)
我建议在您的按钮和链接中添加var AppContainer = React.createClass({
// state management in here
render: function () {
let navHeader = this.state.isAuth ? <Header /> : '';
return (
<div>
{navHeader}
<RouteHandler />
</div>
);
}
});
属性,以便使用Javascript更轻松地访问它们。我们假设您将id
分配给按钮,id="myButton"
分配给锚标记:
id="myLink"
答案 2 :(得分:0)
希望这段代码有用
document.getElementById('click').onclick = function(event){
// on click prevent the default behavior
event.preventDefault();
document.getElementsByClassName('btn-primary')[0].disabled = false;
}
答案 3 :(得分:0)
你去:
$(document).ready(function(){
$("a").click(function(){
$("button[type='submit']").removeAttr('disabled');
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<a href="link" target="_blank"><div class="well">
<span> blabla </span>
<div></a>
<button type="submit" class="btn-primary btn-lg" disabled="disabled"> Blabla </button>