繁体   English   中英

单击提交按钮时无功能

[英]No function when submit button is clicked

这是我的代码:

<head>

<script>input[type=text] {
    padding:5px;
    border:2px solid #000080;
    -webkit-border-radius: 5px;
    border-radius: 5px;
}
input[type=text]:focus {
    border-color:#ccc;
}
-webkit-border-radius: 5px;
 border-radius: 5px;

}
.rows {
    text-align: center;
}</script>

<script>var btn = document.getElementsByTagName("button")[0];
var inpt = document.getElementsByName("post")[0];

function openBox() {
   document.getElementById('postBox').style.display = "block";
}

btn.onclick = function () {

    if (!inpt.value) alert("Please enter something to post.");

    var tbl = document.getElementsByTagName("table")[0];
    var row = tbl.insertRow(0);
    var cell = row.insertCell(0);
    var txt = document.createTextNode(inpt.value);
    cell.appendChild(txt);
    tbl.insertRow(0);
    tbl.insertRow(0);

    inpt.value = "";

};</script>

</head>

<body>

<input type="button" name="answer" value="post" onclick="openBox()" />

<div id="postBox" style="display:none;">
<center>
    <input type="text" name="post" maxlength="100" />
    <br>
    </br>
    <button style="border : solid 0px #000080; border-radius : 4px; moz-border-radius : 4px; -webkit-box-shadow : 0px 0px 5px rgba(0, 0, 0, 1.0); -moz-box-shadow : 0px 0px 5px rgba(0,0,0,1.0); box-shadow : 0px 0px 5px rgba(0,0,0,1.0); font-size : 24px; font-style : ;color : #ffffff; padding : 4px 10px; background-color : #000080;">post</button>
    <br/>
    <br/>
    <center>
    <table class="rows"></table>
</center>
</center>
</div>

</body>

</html>

一切都很好,但是当您要“发布”某些东西时,不会采取任何措施,这与下面的我的JSFiddle不同。

我的JSFiddle( http://jsfiddle.net/yqh2rqh0/25/ )可以正常工作,但网页版本却无法正常工作。

第一个问题:

Uncaught SyntaxError: Unexpected token {

是因为您的CSS是使用<script></script>标签而不是<style></style>进行调用的

<script> <-------- change to style
input[type=text] {
    padding:5px;
    border:2px solid #000080;
    -webkit-border-radius: 5px;
    border-radius: 5px;
}
input[type=text]:focus {
    border-color:#ccc;
}
-webkit-border-radius: 5px;
 border-radius: 5px;

}
.rows {
    text-align: center;
}
</script> <----- change to style

第二期:

Uncaught TypeError: Cannot set property 'onclick' of undefined

是因为您的javascript需要在</body>之前的页面底部而不是<head></head>的顶部加载(就像您的小提琴正在加载No wrap - In <body>)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM