如何关闭字母按钮? [英] how to turn off letter buttons?

查看:134
本文介绍了如何关闭字母按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面的代码中有一堆字母按钮:

Got a bunch of letter buttons in code below:

<?php
    $a = range("A","Z");
?>

<table id="answerSection">
    <tr>

<?php
    $i = 1;
    foreach($a as $key => $val){
        if($i%7 == 1) echo"<tr><td>";
        echo"<input type=\"button\" onclick=\"btnclick(this);\" value=\"$val\" id=\"answer".$val."\" name=\"answer".$val."Name\" class=\"answerBtns answers answerBtnsOff\">";      
        if($i%7 == 0) echo"</td></tr>";
        $i++;
    }
?>
    </tr>
</table>

现在,以下代码可以打开答案按钮:

Now the code below is able to turn on an answer button:

$('#answer'+btn).addClass("answerBtnsOn");

但我想做的是能够打开一些答案按钮并转动另一个答案按钮关闭。

But what I want to do is to be able to turn some answer buttons on and turn the other answer buttons off.

例如,如果答案是A,那么我希望按钮A打开以上代码行,但我想要所有其他字母按钮关掉。如何关闭其他字母按钮?

For example if the Answer is A, then I want button "A" to turn on which the above line of code does but I want all of the other letter buttons to turn off. How can I turn off the other letter buttons?

此处的代码将关闭字母按钮 addClass(answerBtnsOff);

The code here will turn off the letter buttons addClass("answerBtnsOff");,

更新:

我也遇到了一些问题。如果答案是A,则打开字母按钮A,这很好,但如果答案是BD,那么它应该打开字母按钮B和D,但它不会 t打开任何按钮。有谁知道这是为什么?

I have a little problem as well. If the "Answer" is A, then the letter button "A" is turned on which is fine, but if the Answer is "B D", then it should turn on letter buttons "B" and "D" but instead it doesn't turn any buttons on. Does anybody know why this is?

推荐答案

尝试以下选择器组合:

$('#answer'+btn1+', #answer'+btn2).addClass("answerBtnsOn").removeClass("answerBtnsOff");
$('[id^="answer"]').not('#answer'+btn1+', #answer'+btn2).addClass("answerBtnsOff").removeClass("answerBtnsOff");

这篇关于如何关闭字母按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆