I have this script:
<script>
var prop = document.getElementById('div1').firstChild.getAttribute("id");
function aler()
{
alert(prop);
}
</script>
进出脚本标签:变量未定义使用时警报()
<div id="div1">some content</div>
<button onclick="aler()"></button>
有人能向我解释为什么当我按一下按钮,它说:“未定义”
更正: 在div中拖动图片:
<img id="C" src="C.png" draggable="true" ondragstart="drag(event)" width="91px" height="91px">
例如。
function passName(locationID) { \t el1 = document.getElementById('div1')。firstChild.getAttribute(“id”); \t \t el2 = document.getElementById('div2')。firstChild.getAttribute(“id”); \t locationID.innerHTML = el1 +“and”+ el2; \t alert(el1); \t } 这是一个函数,el1和el2被定义为prop变量。但是,当我提醒他们,一个值显示......并对大量的更正感到抱歉 - 我无法解释很好...... – user2874096