[英]Disabling a button through jQuery doesn't work
This is my HTML code: 这是我的HTML代码:
<div class='button' id='next'><a href='#'>Next</a></div>
<div class='button' id='prev'><a href='#'>Previous</a></div>
The button next
must be disabled until something is selected 在选择某些内容之前,必须禁用next
按钮
JQUERY code: JQUERY代码:
if (isNaN(selections[questionCounter])) {
$('#next').attr('disabled', 'disabled');
}
else {
questionCounter++;
displayNext();
}
I don't know how I can fix this. 我不知道该如何解决。 I need something like that one http://www.revillweb.com/demos/jQueryDisableButton/jqueryDisableButton.html 我需要类似的东西http://www.revillweb.com/demos/jQueryDisableButton/jqueryDisableButton.html
Disable on a div
is a non-sense. 在div
上禁用是没有意义的。
You need to use a button
in order to be able to disable it : 您需要使用一个button
才能将其禁用:
<button class='button' id='next'>Next</button>
<button class='button' id='prev'>Previous</button>
Also use JQuery to catch onClick event. 还可以使用JQuery捕获onClick事件。
There is no standard way to 'disable' <a>
or <div>
. 没有“禁用” <a>
或<div>
标准方法。 But you can .unwrap()
the <a>
. 但是您可以.unwrap()
<a>
。
<div class='button' id='next'><a href='#'>Next</a></div>
<div class='button' id='prev'><a href='#'>Previous</a></div>
<script>
if (isNaN(selections[questionCounter])) {
$('#next').contents().unwrap();
}
else {
questionCounter++;
displayNext();
}
</script>
Like it was say you need to have button
for use disabled
property. 就像有人说您需要具有“ disabled
使用”属性button
。
Other possibility if you realy want to stay with your div
and a
: 如果您确实想与div
和a
在一起,还有其他可能:
<script>
if (isNaN(selections[questionCounter])) {
$('#next a').click(function(e) { e.preventDefault(); };
}
else {
questionCounter++;
displayNext();
}
</script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.