Javascript 无法从段落(<;p>;<;/p>;)中的脚本中获取值
window.onload=函数(){ document.getElementById('cityName')。value=GetDivElement(); } 在上面的代码中,我无法调用段落中的“GetDivElement”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
<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>