使用用户脚本从表中单击td

时间:2019-02-23 01:04:40

标签: javascript userscripts

它看起来像一个单选按钮,但实际上只是一个td。我知道如何选择常规单选按钮,但是如何选择td?

$('input [value =“ no”]')。click();


这是表代码的样子:

<table align="center" width="90%" class="hoverTable">
                <tr style="height: 50px">
                    <td width="85%"><span title="Commonsense about social situations. For example: situations that involve other people and evoke emotions of anger, laughter etc." class="tt">Social Commonsense</span>?</td>
                    <td align="center" width="8%">
                        YES
                    </td>
                </tr>

                <tr style="height: 50px">
                    <td><span title="Commonsense about the physical world. E.g. cars are smaller than garages." class="tt">Physical Commonsense</span>?</td>
                    <td align="center">
                        NO
                    </td>
                </tr>

                <tr style="height: 50px">
                    <td><span title="Commonsense about the biological world. For example: plants are fixed in location, people need to eat food to survive etc." class="tt">Biological Commonsense</span>?</td>
                    <td align="center">
                        NO
                    </td>
                </tr>

                <tr style="height: 50px">
                    <td><span title="Commonsense about how the world works. For example: countries have states, babies crawl before walking etc." class="tt">Man-Made Constructs Commonsense</span>?</td>
                    <td align="center">
                        YES
                    </td>
                </tr>

                <tr style="height: 50px">
                    <td><span title="The order in which events occur in time. For example: you need to turn ignition on before driving a car" class="tt">Temporal Order</span> of events?</td>
                    <td align="center">
                        NO
                    </td>
                </tr>

                <tr style="height: 50px">
                    <td><span title="Commonsense about which agent / person performs the required action. For example: If Person1 apologizes to Person2, Person2 accepts the apology, not Person1." class="tt">Agent-Action Commonsense</span>?</td>
                    <td align="center">
                        NO
                    </td>
                </tr>
                <tr style="height: 50px">
                    <td><span title="Commonsense about where certain events can happen. For example: people typically eat in a restaurant, play in the park etc." class="tt">Spatial / Location Commonsense</span>?</td>
                    <td align="center">
                        NO
                    </td>
                </tr>
            </table>

1 个答案:

答案 0 :(得分:1)

我想您使用jQuery吗?

   $('.hoverTable td').click(function() {
    var inVal =  $(this).html();
    var newVal = inVal=='NO'?'YES':'NO';
    $(this).html(newVal)
   });