Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/456.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/75.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 如何为输入框指定值?使用getElementById_Javascript_Html - Fatal编程技术网

Javascript 如何为输入框指定值?使用getElementById

Javascript 如何为输入框指定值?使用getElementById,javascript,html,Javascript,Html,如何向输入框添加值?我正在使用Firefox HTML 工作正常-您只需等待DOM加载完毕: <html> <head> <script> function CycleCount(){ document.getElementById("dgAgentFirstPass_ctl02_txtQuantity").value = 1; } window.onload = function(){

如何向输入框添加值?我正在使用Firefox

HTML


工作正常-您只需等待DOM加载完毕:

<html>
  <head>

    <script>
      function CycleCount(){
        document.getElementById("dgAgentFirstPass_ctl02_txtQuantity").value = 1;
      } 
      window.onload = function(){
        CycleCount(); 
      }
    </script>
  </head>
  <body>
    <input name="dgAgentFirstPass$ctl02$txtQuantity" type="text" id="dgAgentFirstPass_ctl02_txtQuantity" class="inputbox" onkeypress="keyInputForPhone();" style="width:50px;text-align: right" />
  </body>
</html>

函数CycleCount(){
document.getElementById(“dgAgentFirstPass_ctl02_txtQuantity”).value=1;
} 
window.onload=函数(){
循环计数();
}

工作正常-您只需等待DOM加载完毕:

<html>
  <head>

    <script>
      function CycleCount(){
        document.getElementById("dgAgentFirstPass_ctl02_txtQuantity").value = 1;
      } 
      window.onload = function(){
        CycleCount(); 
      }
    </script>
  </head>
  <body>
    <input name="dgAgentFirstPass$ctl02$txtQuantity" type="text" id="dgAgentFirstPass_ctl02_txtQuantity" class="inputbox" onkeypress="keyInputForPhone();" style="width:50px;text-align: right" />
  </body>
</html>

函数CycleCount(){
document.getElementById(“dgAgentFirstPass_ctl02_txtQuantity”).value=1;
} 
window.onload=函数(){
循环计数();
}
var btn=document.getElementById(“btn”);
btn.onclick=函数(){
document.getElementById(“dgAgentFirstPass_ctl02_txtQuantity”).value=1;
}

按钮
var btn=document.getElementById(“btn”);
btn.onclick=函数(){
document.getElementById(“dgAgentFirstPass_ctl02_txtQuantity”).value=1;
}

按钮
好的,问题是main
index.html上的
frameset


index.html

好的,问题是main
index.html


index.html


代码没有问题。在按键时,您正在调用此onkeypress=“keyInputForPhone();”,在哪里调用CycleCount()??你能进入这个方法吗?我没有访问@Jayanth的权限,我只是想使用Firefox add-onshow-about-window.onload=function(){document.getElementById(“dAgentFirstPass_-ctl02_-txtQuantity”)。向清单网站上长长的输入框列表添加值。值=1;}…这对你有用吗?你定义的js函数是
cyclecoount()
,你调用的函数是
onkeypress
keyInputForPhone()
代码没有问题。在按键时你调用的是onkeypress=“keyInputForPhone();”,你在哪里调用cyclecoount()??你能进入这个方法吗?我没有访问@Jayanth的权限,我只是想使用Firefox add-onshow-about-window.onload=function(){document.getElementById(“dAgentFirstPass_-ctl02_-txtQuantity”)。向清单网站上长长的输入框列表添加值。值=1;}…这对您有用吗?您定义的js函数是
CycleCount()
,您调用的函数是
onkeypress
keyInputForPhone()
<html>
  <head>

    <script>
      function CycleCount(){
        document.getElementById("dgAgentFirstPass_ctl02_txtQuantity").value = 1;
      } 
      window.onload = function(){
        CycleCount(); 
      }
    </script>
  </head>
  <body>
    <input name="dgAgentFirstPass$ctl02$txtQuantity" type="text" id="dgAgentFirstPass_ctl02_txtQuantity" class="inputbox" onkeypress="keyInputForPhone();" style="width:50px;text-align: right" />
  </body>
</html>
<!DOCTYPE html>

<html lang="en" xmlns="http://www.w3.org/1999/xhtml">

<head>
    <meta charset="utf-8" />
    <title>Test Page</title>   
</head>

<frameset cols="250,*">
    <frame src="left.html" name="LEFTFRAME">
    <frame src="right.html" name="RIGHTFRAME">
</frameset>

</html>
<!DOCTYPE html>

<html lang="en" xmlns="http://www.w3.org/1999/xhtml">

  <head>
    <meta charset="utf-8" />
    <title>Left</title>
  </head>

  <body>
    Left Frame
  </body>

</html>
<!DOCTYPE html>

<html lang="en" xmlns="http://www.w3.org/1999/xhtml">

  <head>
    <meta charset="utf-8" />
    <title>Right</title>
  </head>

  <body>
    Right Frame
    <br>

    <input name="dgAgentFirstPass$ctl02$txtQuantity" id="dgAgentFirstPass_ctl02_txtQuantity" class="inputbox" style="width:50px;text-align: right" type="text">

  </body>

</html>
function CycleCount(){
        document.getElementsByName("RIGHTFRAME")[0].contentWindow.document.getElementById("dgAgentFirstPass_ctl02_txtQuantity").value = 1;
    }