输出消失的Javascript简单的innerHTML [英] Output disappeared Javascript simple innerHTML

查看:84
本文介绍了输出消失的Javascript简单的innerHTML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是javascript新手,在每件简单的事情上我都遇到了某种问题,但这对我来说似乎无法解决.我用谷歌搜索,没有任何相似之处.

I am new to javascript and on every simple thing i get some kind of problem but this seems un-solve-able to me. I googled and nothing simillar.

在我将数据输入到文本框中并将其存储到变量中之后,我在段落中打印出了变量. 问题是我输出的输出在不到一秒的时间内消失了.代码似乎很正常,可能是什么?当您不放置getch()时,它看起来像c; 预先感谢.

After i input data into textbox and store it into variable, i print out variable in paragraph. Problem is that output i printed out disappears within less than second. Code seems to be normal, what might it be? It looks like c when you dont put getch(); Thanks in advance.

<form>Unesite broj koji ce se ispisat kasnije.<br>
<input type="text" id="userInput">
<input type="submit" name="unos" value="Unesi i ispisi" onclick="unesi()"><br><br>

</form> 
    <br><br>
<p>Unjeli ste <b id="ispis"></b></p>
<script>
function unesi(){
var userInput = document.getElementById('userInput').value;
document.getElementById('ispis').innerHTML = userInput;
}   

</script>

推荐答案

<form>标记未指定action属性,因此,当您单击提交"按钮时,浏览器会将表单提交到当前URL. -看起来很像页面正在刷新.

The <form> tag doesn't specify an action attribute, so when you click the submit button, the browser will submit the form to the current URL - which will look a lot like the page is refreshing.

如果要在用户单击提交"时运行unesi函数,并阻止HTML表单提交,则需要对其进行一些更改:

If you want to run the unesi function when the user clicks submit and prevent the HTML form from submitting, you need to change it slightly:

<input type="submit" name="unos" value="Unesi i ispisi"
      onclick="unesi(); return false;">

return false阻止表单提交自己.

这篇关于输出消失的Javascript简单的innerHTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆