Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/393.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 无法从段落(<;p>;<;/p>;)中的脚本中获取值_Javascript - Fatal编程技术网

Javascript 无法从段落(<;p>;<;/p>;)中的脚本中获取值

Javascript 无法从段落(<;p>;<;/p>;)中的脚本中获取值,javascript,Javascript,window.onload=函数(){ document.getElementById('cityName')。value=GetDivElement(); } 在上面的代码中,我无法调用段落中的“GetDivElement” <p><input type="text" name="adcode" id="cityName" style="border:none;color:green;"/></p> <scri

window.onload=函数(){ document.getElementById('cityName')。value=GetDivElement(); } 在上面的代码中,我无法调用段落中的“GetDivElement”

<p><input type="text" name="adcode" id="cityName" 
         style="border:none;color:green;"/></p>
        <script>
          window.onload = function() {
              document.getElementById('cityName').value = GetDivElement();
            }  
        </script>


如何在p id中传递GetElementId???

如果要将
GetDivElement()
方法的返回值传递到段落,可以按如下方式执行:

window.onload=function(){
让getDivElement=()=>{
返回“Div元素数据”;
};
让inputbox=document.getElementById('cityInput');
让cityParagraph=document.getElementById('cityValue');
inputbox.value=cityParagraph.innerHTML=getDivElement();
}


您不能有重复的ID,GetDivElement在哪里?只有输入元素具有
将具有innerText/innerHTML或text内容
id=“cityName”
将用于
p
输入
?!如果我理解正确,您想将getDivElement作为输入字段的值传递吗?你能解释一下你想用这个完成什么吗?(触发函数,在某个事件上触发函数)?是否需要获取文本框中的值以显示在段落中?如果GetDivElement()=coimbatore,则需要获取段落中的值。我只能在文本框中获取值。如果没有文本框,我想在

<p id="cityName"></p>