gpt4 book ai didi

javascript - 如何使用 jquery/javascript 在 asp.net c# 中禁用单选按钮单击上的链接按钮

转载 作者:行者123 更新时间:2023-12-02 22:01:04 24 4
gpt4 key购买 nike

  function disableButtons(val) {
if (val == 'clear') {
$('#btnExcellent, #btnFine, #btnBad').prop('disabled', true);

$('#btnSkip').prop('disabled', false);
} else {
$('#btnExcellent, #btnFine, #btnBad').removeProp('disabled');
$('#btnSkip').prop('disabled',true);
}
}
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"></script>
<table id="radioBtnQueryQuality">
<tr>
<td><input id="radioBtnQueryQuality_0" type="radio" name="radioBtnQueryQuality" value="clear" onclick="disableButtons(&#39;clear&#39;);" /><label for="radioBtnQueryQuality_0">One</label></td>
</tr>
<tr>
<td><input id="radioBtnQueryQuality_1" type="radio" name="radioBtnQueryQuality" value="notExpNorImp" onclick="disableButtons(&#39;notExpNorImp&#39;);" /><label for="radioBtnQueryQuality_1">Two</label></td>
</tr>
<tr>
<td><input id="radioBtnQueryQuality_2" type="radio" name="radioBtnQueryQuality" value="invalid" onclick="disableButtons(&#39;invalid&#39;);" /><label for="radioBtnQueryQuality_2">Three</label></td>
</tr>
</table>

<a id="btnExcellent" class="btn btn-primary" href="javascript:__doPostBack(&#39;btnExcellent&#39;,&#39;&#39;)">Excellent</a>
<a id="btnFine" class="btn btn-primary" href="javascript:__doPostBack(&#39;btnFine&#39;,&#39;&#39;)">Fine</a>
<a id="btnBad" class="btn btn-primary" href="javascript:__doPostBack(&#39;btnBad&#39;,&#39;&#39;)">Bad</a>
<a id="btnSkip" class="btn btn-primary" href="javascript:__doPostBack(&#39;btnSkip&#39;,&#39;&#39;)">Skip</a>

要求:

我想在单击第一个单选按钮(即值为 one)时禁用 btnFour 按钮。如果我单击其余两个单选按钮,我希望禁用除最后一个之外的前三个按钮。

它没有按照我想要的方式工作。如果我使用简单的 HTML 按钮,那么它可以工作,但对于 LinkBut​​tons 则不起作用。任何帮助将不胜感激。

谢谢。

最佳答案

您可以尝试下面的代码,只需在调用禁用函数时传递单选按钮的值即可启用或禁用相关按钮

代码片段

function disableButtons(val) {
if (val == 'clear') {
$('#btnExcellent, #btnFine, #btnBad').addClass('disabled');
$('#btnSkip').removeClass('disabled');
} else {
$('#btnExcellent, #btnFine, #btnBad').removeClass('disabled');
$('#btnSkip').addClass('disabled');
}

$('a.disabled').each(function(){
var href = $(this).attr('href');
//console.log('attr = ' + href);
$(this).data('href', href);
$(this).attr('href', '#')
});
$('a:not(.disabled)').each(function(){
var href = $(this).data('href');
//console.log('data = ' + href);
if(href) {
$(this).attr('href', href);
}
});
}
a.disabled {
opacity: 0.1;
}
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"></script>
<table id="radioBtnQueryQuality">
<tr>
<td><input id="radioBtnQueryQuality_0" type="radio" name="radioBtnQueryQuality" value="clear" onclick="disableButtons(&#39;clear&#39;);" /><label for="radioBtnQueryQuality_0">One</label></td>
</tr>
<tr>
<td><input id="radioBtnQueryQuality_1" type="radio" name="radioBtnQueryQuality" value="notExpNorImp" onclick="disableButtons(&#39;notExpNorImp&#39;);" /><label for="radioBtnQueryQuality_1">Two</label></td>
</tr>
<tr>
<td><input id="radioBtnQueryQuality_2" type="radio" name="radioBtnQueryQuality" value="invalid" onclick="disableButtons(&#39;invalid&#39;);" /><label for="radioBtnQueryQuality_2">Three</label></td>
</tr>
</table>

<a id="btnExcellent" class="btn btn-primary" href="javascript:__doPostBack(&#39;btnExcellent&#39;,&#39;&#39;)">Excellent</a>
<a id="btnFine" class="btn btn-primary" href="javascript:__doPostBack(&#39;btnFine&#39;,&#39;&#39;)">Fine</a>
<a id="btnBad" class="btn btn-primary" href="javascript:__doPostBack(&#39;btnBad&#39;,&#39;&#39;)">Bad</a>
<a id="btnSkip" class="btn btn-primary" href="javascript:__doPostBack(&#39;btnSkip&#39;,&#39;&#39;)">Skip</a>

关于javascript - 如何使用 jquery/javascript 在 asp.net c# 中禁用单选按钮单击上的链接按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59872659/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com