我想在警报框中显示变量值.
请看下面的代码:
<script>
function check() {
var content = document.getElementById("one").value;
alert(content);
}
</script>
<body onload="check()">
<div style="position: absolute; z-index: 9; width: 450px; top: 38px; margin-left: 176px;">
<style>
div#layout {
margin:0px;
padding:px;
width:450px;
margin:0px auto;
overflow:hidden;
}
</style>
<div id="layout">
<span id="one" style="display:none" ph="layout1" class="ione">yes</span>
<span id="two" style="display:none" ph="layout1" class="ione">no</span>
</div>
</div>
</body>
当我执行此代码时,它在警报框中显示未定义的值.
跨度id“一”的值在不同的情况下发生变化.
我想跟踪每一次…所以我不能硬编码.
你能帮忙吗?
解决方法
跨越没有html的价值
一个是跨标签的ID
在javascript使用
document.getElementById('one').innerText;
在jQuery中使用
$('#one').text()
function check() {
var content = document.getElementById("one").innerText;
alert(content);
}
要么
function check() {
var content = $('#one').text();
alert(content);
}