Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/470.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
javascript输入值在手动输入后不更新_Javascript_Input - Fatal编程技术网

javascript输入值在手动输入后不更新

javascript输入值在手动输入后不更新,javascript,input,Javascript,Input,如果我在t1中输入了一些内容,t2就会改变。 但如果t2已经有手动输入,则不再更改(反之亦然) 如何更改已使用javascript手动输入的输入字段(无需重新加载页面!) 如果输入字段已经有输入,则不会更改 t1: t2: 函数upd1(){ t2.设置属性(“值”、“更改”); 返回true; } 函数upd2(){ t1.设置属性(“值”、“更改”); 返回true; } 简单的答案是使用以下方法: 函数upd1(){ t2.value=‘已更改’; 返回true; } 函数upd2(

如果我在t1中输入了一些内容,t2就会改变。
但如果t2已经有手动输入,则不再更改(反之亦然)

如何更改已使用javascript手动输入的输入字段(无需重新加载页面!)


如果输入字段已经有输入,则不会更改

t1:

t2: 函数upd1(){ t2.设置属性(“值”、“更改”); 返回true; } 函数upd2(){ t1.设置属性(“值”、“更改”); 返回true; }
简单的答案是使用以下方法:

函数upd1(){
t2.value=‘已更改’;
返回true;
}
函数upd2(){
t1.value=‘已更改’;
返回true;
}
t1:


t2:
您还可以保存每个字段的旧值以继续编辑。此外,每次它都会在另一个字段上显示编辑状态。对用户来说会更舒适

inputfields不会更改,如果它们已经有了输入



让firstElValue=''; 让secondalvalue=''; 函数upd1(){ 设el=document.querySelector('#t2'); el.value=‘已更改’; 返回true; } 函数upd2(){ 设el=document.querySelector('#t1'); el.value=‘已更改’; 返回true; } 函数renderFirstEl(){ 设el=document.querySelector('#t1'); secondElValue=document.querySelector('#t2').value; el.value=第一个ELVALUE; } 函数renderConnel(){ 设el=document.querySelector('#t2'); firstElValue=document.querySelector('#t1').value; el.value=第二个值; }
我很困惑,即使不向
t1
t2
声明和赋值,代码是如何工作的。有人知道吗?
<!DOCTYPE html>
<html>
<body>

inputfields are not changed, if they have/had an input already!<br />
<br />
t1: <input type="text" id="t1" value="" onchange="upd1()"><br /><br />
t2: <input type="text" id="t2" value="" onchange="upd2()">

<script>
function upd1() {
  t2.setAttribute("value", "changed");
  return true;
}

function upd2() {
  t1.setAttribute("value", "changed");
  return true;
}
</script>

</body>
</html>