javascript改变按钮的值 [英] javascript change value of button
本文介绍了javascript改变按钮的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何更改此按钮的值?
< form name =我在看教程,但只看到网址改变了,而不是按钮。 formid =form>
< button name =buttonid =button> Click Me!< / button>
< / form>
< script type =text / javascript>
document.form.button.value = new Date();
< / script>
解决方案
我在按钮上添加了一个onclick以更改值如果你添加 onsubmit =return false
到form标签,它不会刷新页面。
< form name =formid =formonsubmit =return false>
< button name =buttonid =buttononclick =changeValue(); value =before> Click Me!< / button>
< / form>
< script type =text / javascript>
function changeValue()
{
//更改按钮的值
document.form.button.value = new Date();
//更改按钮上的文本
document.form.button.innerHTML = new Date();
}
< / script>
How do I change the value of this button? I am looking at a tutorial, but only the url seems to change, and not the button.
<form name="form" id="form">
<button name="button" id="button">Click Me!</button>
</form>
<script type="text/javascript">
document.form.button.value=new Date();
</script>
解决方案
I added an onclick to your button to change the value with the function.
If you add onsubmit="return false"
to the form tag, it won't refresh the page.
<form name="form" id="form" onsubmit="return false">
<button name="button" id="button" onclick="changeValue();" value="before" >Click Me!</button>
</form>
<script type="text/javascript">
function changeValue()
{
// Changes the value of the button
document.form.button.value = new Date();
// Changes the text on the button
document.form.button.innerHTML = new Date();
}
</script>
这篇关于javascript改变按钮的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文