如何更改此按钮的值?我正在查看教程,但似乎只有 url 发生了变化,而按钮没有。
<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>
最佳答案
我向您的按钮添加了一个 onclick 以使用该函数更改值。
如果在表单标签中添加onsubmit="return false"
,它不会刷新页面。
<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改变按钮的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10215792/