如何在用户使用jquery单击按钮(提交选项之前)时突出显示html中的选项

2024-07-06 18:59:44 发布

您现在位置:Python中文网/ 问答频道 /正文

嗨,你能帮我解决以下问题吗? 我正在用django编写一个web应用程序。我想在一个页面中实现以下功能:当用户单击单选按钮时,该选项将被突出显示。如图所示:

page illustration

在表格.py我有

class AnswerForm(forms.Form):
    ANSWER_CHOICES = (
        (1, 'Lottery 1'),
        (2, 'Lottery 2'),
    )
    answer = forms.ChoiceField(choices=ANSWER_CHOICES, widget=forms.RadioSelect)
    question = forms.IntegerField(widget=forms.HiddenInput)

我的html如下。你知道吗

<!DOCTYPE html>
<html lang="en">

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

 <head>
      <title>Two lotteries</title>
   </head>
<body>
       <table BORDER=1 WIDTH="40%" HEIGHT="40%" border = "1" bordercolor = "green">
         <tr>
            <td>  </td>
            <th>State 1</th>
               <th>State 2</th>
               <th>State 3</th>
         </tr>

           <tr bgcolor = "white" >
            <td>Lottery 1</td>
            <td>{{ problem.0 }}{{ sltlottery }}</td>
             <td>{{ problem.1 }} </td>
             <td>{{ problem.2 }}</td>
         </tr>

           <tr>
            <td>Lottery 2</td>
            <td> {{ problem.3 }} </td>
             <td> {{ problem.4 }} </td>
             <td> {{ problem.5 }} </td>
         </tr>

      </table>

   </body>
<form action=" " method="post">
    {% csrf_token %}
    {{ form.as_p }}
    <input name="sellottery" type="submit" value="Submit">
</form>

我在网上搜索了一下,有人建议用jquery来读取点击按钮的值。你知道吗

<script>
$('input[name="sellottery"]:checked').val();
</script>

有人能告诉我上面这行的值是1还是2吗?如何在java脚本中编写以下逻辑语句并将其传递给html:当值为1时,bgcolor=“yellow”?你知道吗

非常感谢!你知道吗


Tags: answerformhtmlscriptajaxformswidgetjquery