更新输入值[HTML / JS] [英] Updating input value [HTML/JS]

查看:80
本文介绍了更新输入值[HTML / JS]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在更新输入字段[HTML]中的值时遇到了问题。
是否可以在更改时更新它们?我试图这样做(我使用的代码是我在本站找到的): id ='user'value ='user'onchange =updateInput(this.value)>< br>

< script>
var cc2 = document.getElementById(user)。value;

函数updateInput(ish){
document.getElementById(user)。value = ish;
}
< / script>

< a href =#onclick =alert(cc2)>测试< / a>

按下测试链接后,我仍然收到警报值:user,无论我请将您的updateInput更新为以下代码:



<$>



$ b

 函数updateInput(ish){
cc2 = ish;
}

这会将输入的值赋值给cc2 var。因此,每次输入更改都会使cc2保持最新值。


I have got a problem with updating values in input filed [HTML]. Is it possible to update them on change? I tried to do it this way (i used code that i found on this site):

<input type="text" id='user' value='user' onchange="updateInput(this.value)"><br>

<script>
var cc2 = document.getElementById("user").value;

function updateInput(ish){
document.getElementById("user").value = ish;
}
</script>

<a href="#" onclick="alert(cc2)">test</a>

After pressing "test" link I am still receiving alert with value: "user" no matter what i put in input.

解决方案

Please update your updateInput with following code

function updateInput(ish){
cc2=ish;
}

This will assign the value of your input to cc2 var. So on each change in input will make cc2 to holds the latest value.

这篇关于更新输入值[HTML / JS]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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