为什么JavaScript会跳过我的功能?

rix*_*ter 0 javascript

这是我想知道的那些日子之一:我是否会失去理智?如果我单步执行这个简单的javascript函数,执行将从第3行跳到第7行.

function editStudy() { 
        var studyindex = document.StudyMaint.StudyList.selectedIndex;
        var studyabrv = document.StudyMaint.StudyList[index].text;  //Line 3
        var msg="Edit study "+studyabrv+"?";

        // Get the Study record id was selected in the picklist,
        // then go to Study edit screen, then

        if (confirm(msg)) {
            location.href="editStudy.php?action=UPDATE&studyindex="+studyindex+"&studyabrv="+studyabrv;
        }  //Line 7
    }
Run Code Online (Sandbox Code Playgroud)

但是我的表格StudyMaint被定义为:

<body>
    <?php showUserLine(); ?>
    <form name="StudyMaint" action="Process_StudyMaint.php" method="POST" onsubmit="return false">
    <div id="dataentrybox"> 
        <div id="innerbox">
            <div align="center">
...
Run Code Online (Sandbox Code Playgroud)

有人看到我在这里做错了吗?

小智 6

您似乎使用了错误的索引变量名称.尝试使用你定义的那个,studyindex.