Onclick没有做任何事情

时间:2017-04-13 21:24:53

标签: javascript html onclick

所以在这里,我浪费了几个小时的时间来解决这个问题。我有一个更大的功能不工作,所以我决定测试这个小的,但它也没有工作。没有错误,但点击按钮后没有任何事情发生。

<form>
            <input type="text" id="textField">
            <input id="filtrooo" type="submit" value="Click">
    </form>
<script>
        document.getElementById("filtrooo").onclick = function(){
            document.getElementById("textField").innerHTML ="txt";  
        };
</script>

这里有什么问题?

3 个答案:

答案 0 :(得分:1)

现在已经开始了:

&#13;
&#13;
#include <stdio.h>
#include <string.h>

// function declaration
int min_hour(int hour[int n]);  

int main()
{
    int hour[5] = {8, 8, 9, 8, 8};
    int j = min_hour(hour[5]);
    printf("%d", j);
}

int min_hour(int hour[int n])
{
    int earliest = 0;
    for (int i = 1; i <= n + 1; i++)
    {
        if (hour[i] < hour[i+1])
        {
            earliest = i;
        }
        else
        {
            earliest = i+1;
        }
    }
    return earliest;
}

Line Col    
5   24  [Error] expected expression before 'int'
10  3   [Warning] implicit declaration of function 'min_hour' [-Wimplicit-function-declaration]
14  24  [Error] expected expression before 'int'
&#13;
&#13;
&#13;

而不是<form> <input type="text" id="textField"> <input id="filtrooo" type="button" value="Click"> </form> <script> document.getElementById("filtrooo").onclick = function(){ document.getElementById("textField").value = "txt"; }; </script>你应该写innerHTML。另一个问题是,当您单击“提交”按钮时,页面将刷新并且输入的值将清除。因此,我使用value

而不是type="submit"

答案 1 :(得分:0)

试试这个:

darker2:~/workspace (master) $ ./server
./server: /usr/lib/x86_64-linux-gnu/libQt5Network.so.5: no version information available (required by ./server)
./server: /usr/lib/x86_64-linux-gnu/libQt5Core.so.5: no version information available (required by ./server)
./server: /usr/lib/x86_64-linux-gnu/libQt5Core.so.5: no version information available (required by ./server)
./server: relocation error: ./server: symbol qt_version_tag, version Qt_5.6 not defined in file libQt5Core.so.5 with link time reference

答案 2 :(得分:0)

首先,使用提交按钮,页面将重新加载,因此您无法查看代码的功能。 然后,不要使用.innerHTML。请改用.value