Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/390.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在评分表中显示名称_Javascript_Html - Fatal编程技术网

Javascript 如何在评分表中显示名称

Javascript 如何在评分表中显示名称,javascript,html,Javascript,Html,有人能帮我处理这个代码吗 我不知道如何在我的成绩表上显示姓名、课程和年份。这只是一个简单的评分系统 代码如下: <table> <tr><td>Student Name:</td><td><input type="text" id="s_n" name="studn"></td></tr> <tr><td>Course and Year:</td><td&

有人能帮我处理这个代码吗

我不知道如何在我的成绩表上显示姓名、课程和年份。这只是一个简单的评分系统

代码如下:

<table>
 <tr><td>Student Name:</td><td><input type="text" id="s_n" name="studn"></td></tr>
 <tr><td>Course and Year:</td><td><input type="text" id="c_y" name="crsy"></td></tr>
 <tr><td>Quiz 1:</td><td><input type="text" id="txt1" name="text1"></td></tr>
 <tr><td>Quiz 2:</td><td><input type="text" id="txt2" name="text2"></td></tr>
 <tr><td>Quiz 3:</td><td><input type="text" id="txt3" name="text3"></td></tr>
 <tr><td><button onclick="myFunction()">Total</button></td></tr>
</table>

 <script>
    function myFunction() {
        var stud = document.getElementById("s_n").value;
        var crs = document.getElementById("c_y").value;
        var a = document.getElementById("txt1").value;
        var b = document.getElementById("txt2").value;
        var c = document.getElementById("txt3").value;
        //var d = document.getElementById("txt4").value;
        var total = parseInt(a) + parseInt(b) + parseInt(c);
        document.getElementById("scores").innerHTML = total;
    }
</script>
<p id="scores"></p>

学生姓名:
课程和年份:
小测验1:
小测验2:
小测验3:
全部的
函数myFunction(){
var stud=document.getElementById(“s_n”).值;
var crs=document.getElementById(“c_y”).值;
var a=document.getElementById(“txt1”).value;
var b=document.getElementById(“txt2”).value;
var c=document.getElementById(“txt3”).value;
//var d=document.getElementById(“txt4”).value;
var-total=parseInt(a)+parseInt(b)+parseInt(c);
document.getElementById(“分数”).innerHTML=总计;
}

在HTML中,您可以添加:

<p id="info"></p>
在HTML中,您可以添加:

<p id="info"></p>

您可以将总计和名称连接在一起,如下所示:

document.getElementById("scores").innerHTML ="Name "+stud+ " total " +total;
<script>
function myFunction() {
    var stud = document.getElementById("s_n").value;
    var crs = document.getElementById("c_y").value;
    var a = document.getElementById("txt1").value;
    var b = document.getElementById("txt2").value;
    var c = document.getElementById("txt3").value;
    //var d = document.getElementById("txt4").value;
    var total = parseInt(a) + parseInt(b) + parseInt(c);

    document.getElementById("scores").innerHTML = "<div><span class='student'>" + stud + "<span class='course'> " + crs + "</span><span class='total'>Total: " + total + " </span>";
}
</script>

参见示例

您可以将总数和名称连接在一起,如下所示:

document.getElementById("scores").innerHTML ="Name "+stud+ " total " +total;
<script>
function myFunction() {
    var stud = document.getElementById("s_n").value;
    var crs = document.getElementById("c_y").value;
    var a = document.getElementById("txt1").value;
    var b = document.getElementById("txt2").value;
    var c = document.getElementById("txt3").value;
    //var d = document.getElementById("txt4").value;
    var total = parseInt(a) + parseInt(b) + parseInt(c);

    document.getElementById("scores").innerHTML = "<div><span class='student'>" + stud + "<span class='course'> " + crs + "</span><span class='total'>Total: " + total + " </span>";
}
</script>

参见示例

您可能希望执行以下操作:

document.getElementById("scores").innerHTML ="Name "+stud+ " total " +total;
<script>
function myFunction() {
    var stud = document.getElementById("s_n").value;
    var crs = document.getElementById("c_y").value;
    var a = document.getElementById("txt1").value;
    var b = document.getElementById("txt2").value;
    var c = document.getElementById("txt3").value;
    //var d = document.getElementById("txt4").value;
    var total = parseInt(a) + parseInt(b) + parseInt(c);

    document.getElementById("scores").innerHTML = "<div><span class='student'>" + stud + "<span class='course'> " + crs + "</span><span class='total'>Total: " + total + " </span>";
}
</script>

函数myFunction(){
var stud=document.getElementById(“s_n”).值;
var crs=document.getElementById(“c_y”).值;
var a=document.getElementById(“txt1”).value;
var b=document.getElementById(“txt2”).value;
var c=document.getElementById(“txt3”).value;
//var d=document.getElementById(“txt4”).value;
var-total=parseInt(a)+parseInt(b)+parseInt(c);
document.getElementById(“分数”).innerHTML=“+stud+”“+crs+”总计:“+Total+”;
}
这将生成给定的HTML:

<div>
    <span class='student'>Student Name</span>
    <span class='course'>Course</span>
    <span class='total'>Total: value</span>
</div>

学名
课程
总计:价值

您可能希望执行以下操作:

document.getElementById("scores").innerHTML ="Name "+stud+ " total " +total;
<script>
function myFunction() {
    var stud = document.getElementById("s_n").value;
    var crs = document.getElementById("c_y").value;
    var a = document.getElementById("txt1").value;
    var b = document.getElementById("txt2").value;
    var c = document.getElementById("txt3").value;
    //var d = document.getElementById("txt4").value;
    var total = parseInt(a) + parseInt(b) + parseInt(c);

    document.getElementById("scores").innerHTML = "<div><span class='student'>" + stud + "<span class='course'> " + crs + "</span><span class='total'>Total: " + total + " </span>";
}
</script>

函数myFunction(){
var stud=document.getElementById(“s_n”).值;
var crs=document.getElementById(“c_y”).值;
var a=document.getElementById(“txt1”).value;
var b=document.getElementById(“txt2”).value;
var c=document.getElementById(“txt3”).value;
//var d=document.getElementById(“txt4”).value;
var-total=parseInt(a)+parseInt(b)+parseInt(c);
document.getElementById(“分数”).innerHTML=“+stud+”“+crs+”总计:“+Total+”;
}
这将生成给定的HTML:

<div>
    <span class='student'>Student Name</span>
    <span class='course'>Course</span>
    <span class='total'>Total: value</span>
</div>

学名
课程
总计:价值
@RenDF-Yeah它将显示“非数字”NaN,因为没有输入数字。@RenDF-Yeah它将显示“非数字”NaN,因为没有输入数字。