0

我正在尝试进行一个基本测验,将下拉菜单与文本块的正确值相匹配。

这是下拉菜单和段落的格式:

<section class = "drop-menu">
    <select id="drop1">
        <option value='0'>Select True or False:</option>
        <option value='1'>T</option>
        <option value='2'>F</option>
    </select>
</section>

<section class="box1" id = "1" name = "T">
    Sed ut perspiciatis, unde omnis iste.
</section>

我正在尝试使用以下方法匹配答案:

<button class="btn btn-primary" onclick=onSubmitClick();> Submit</button>

而这个功能:

function onSubmitClick() {
    var i = document.getElementById("drop1");
    var submOne = i.options[i.selectedIndex].text;

    var w = document.getElementById("1");
    var answrOne = w.name;
    if(submOne === answrOne)
    {
        alert("Correct!");
    }
    else
    {
        alert("Please Try Again!");
    }
}

现在我正在尝试获取部分名称 =“T”,var answrOne = w.name;但它总是说“请再试一次!”,您如何正确获取部分名称以与提交的答案进行比较?谢谢!

4

1 回答 1

4

改变

var answrOne = w.name;

var answrOne = w.getAttribute('name');

jsFiddle 示例

于 2013-08-14T15:56:18.283 回答