自动填充单选按钮

发布于 2024-10-06 23:54:39 字数 275 浏览 1 评论 0原文

不确定这是否是提出这个问题的合适论坛,但我已经没有选择了。

对于一堂课,我们必须参加 300 多个问题的测试,但我们可以无限次地参加这些测试。我想知道是否有一个程序可以根据提出的问题智能地保存单选按钮的状态,这样我就不必逐一回答每个问题。

如果不清楚:每次您参加新的测试时,它都不会保存您上次提交的答案。我想要一种可以根据先前提交自动填充所有单选按钮的方法。

我尝试了 auto_fill 扩展,但所有这些扩展都是基于按钮的 javascript 名称(每次都会更改)。有什么解决办法吗?

Not sure if this is an appropriate forum to ask this question, but I've run out of options.

For a class, we have to take 300+ question tests, but we get to take them an infinite amount of times. I was wondering if there was a program that could intelligently save the status of radio buttons based on the questions asked so that I don't have to go through each question answering them one-by-one.

In case that wasn't clear: Each new time you take the test, it doesn't save what your answer was for the previous submission. I want a way that can auto-fill all the radio buttons based on the previous submission.

I tried an auto_fill extension, but those all of those worked based upon the javascript name of the button (which changes each time). Is there any solution?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

亚希 2024-10-13 23:54:39

鉴于您所说的,这就是我要开始的代码类型。
粘贴到带有单选按钮的页面上的浏览器地址栏中:(

javascript:(function(){var inputElements = document.getElementsByTagName("input");for (var i=0; i<inputElements.length; i++) {if (inputElements[i].getAttribute('type') == 'radio') {inputElements[i].checked = true;}}})();

可读版本):

(function(){
    var inputElements = document.getElementsByTagName("input");

    for (var i=0; i<inputElements.length; i++) {
        if (inputElements[i].getAttribute('type') == 'radio') {
            inputElements[i].checked = true;
        }
    }
})();

此代码将每个单选按钮设置为选中,但由于每组中只能选择一个单选按钮,因此实际结果是最后一个单选按钮每组中的按钮都被选中。不是特别有用,但我可能需要有关单选按钮结构的更多详细信息(每个问题有多少个)才能提出更好的方案。

更进一步,可以编写代码在您填写完所有单选按钮后运行;该代码将生成更多代码,这些代码将为您后续填充单选按钮。

当然,如果您的学校计算机被“锁定”并且您无法使用它们做太多事情,那么这只是一个“明智”的解决方案。

Given what you've said this is the type of code I would start with..
Paste into the address bar of your browser on a page with radio buttons:

javascript:(function(){var inputElements = document.getElementsByTagName("input");for (var i=0; i<inputElements.length; i++) {if (inputElements[i].getAttribute('type') == 'radio') {inputElements[i].checked = true;}}})();

(readable version):

(function(){
    var inputElements = document.getElementsByTagName("input");

    for (var i=0; i<inputElements.length; i++) {
        if (inputElements[i].getAttribute('type') == 'radio') {
            inputElements[i].checked = true;
        }
    }
})();

This code sets every radio button to checked, but as only one radio button in each group can be selected, the actual result is that the last radio button in each group is selected. Not particularly useful, but I would probably need more details about the structure of the radio buttons (how many per question) to come up with anything better.

Taking it further, code could be written to run after you have filled in all the radio buttons once; this code would generate more code which would fill in the radio buttons for you subsequent times.

Of course, this is only a "sensible" solution to pursue if your school computers are "locked down" and you can't do much with them.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文