小编jah*_*han的帖子

如何在外部 javascript 文件中使用 onclick

我在 w3school 上得到以下代码:

<!DOCTYPE html>
<html>
<head>
<script>
function changetext(id)
{
id.innerHTML="Ooops!";
}
</script>
</head>
<body>
<h1 onclick="changetext(this)">Click on this text!</h1>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

这运作良好。现在为了练习,我想通过外部js文件来完成它。我的HTML代码如下:

<!DOCTYPE html>
<html>
<body>

<p>Click the button to execute the <em>displayDate()</em> function.</p>

<button >Try it</button>


<p id="demo"></p>
<script src="function.js"></script>
</body>
</html> 
Run Code Online (Sandbox Code Playgroud)

我的js文件:

function displayDate()
{
    document.getElementById("demo").innerHTML=Date();
}
onclick='displayDate()';
Run Code Online (Sandbox Code Playgroud)

但上面的代码不起作用。为此我该怎么办呢。

html javascript

2
推荐指数
1
解决办法
1万
查看次数

使用malloc时出现分段错误

我在这里问了我的问题C中最大的2-D数组大小以及在得到声明之前我得到的答案是有些人重复的,我修改了我的代码:

#include<stdio.h>
#include<stdlib.h>

int main()
{
    int i,j,n,m,p = 0 ;
    int sum[100000] = {0};

    scanf("%d%d%d",&n,&m,&p);

    /*for ( i = 0 ; i < n ; i++ )
    {
        for( j = 0 ; j < m ; j++ )
        {
            a[i][j] = j + 1 ;
        }
    }*/
    int **a = (int **) malloc(sizeof(int)*n);
    for(i=0; i<n; i++)
    {
        a[i] = (int *) malloc(sizeof(int)*m); 

       for(i=0; i<n; i++){
           for(j=0; j<m; j++){
            a[i][j] = j + 1 ;

           }
       } …
Run Code Online (Sandbox Code Playgroud)

c arrays malloc segmentation-fault

2
推荐指数
1
解决办法
82
查看次数

标签 统计

arrays ×1

c ×1

html ×1

javascript ×1

malloc ×1

segmentation-fault ×1