怎么用JS把DIV表单的value传递给input表单的value
<inputname="mypwd"type="hidden"value=""><divstyle="cursor:text;"class="placeholder"id...
<input name="mypwd" type="hidden" value="">
<div style="cursor:text;" class="placeholder" id="idDiv_PWD_PasswordExample"></div>
这2个传递 展开
<div style="cursor:text;" class="placeholder" id="idDiv_PWD_PasswordExample"></div>
这2个传递 展开
1个回答
展开全部
先给input加个ID,比如:id="mypwd"
直接赋值:
document.getElementById('mypwd').value = document.getElementById('idDiv_PWD_PasswordExample').innerHTML;
直接赋值:
document.getElementById('mypwd').value = document.getElementById('idDiv_PWD_PasswordExample').innerHTML;
更多追问追答
追问
不行诶,我点传递后,这个值是空白的。我把后面改成document.getElementById('idDiv_PWD_PasswordExample').value;
他的值会变成undefined
追答
<body>
<script>
window.onload = function(){document.getElementById('idDiv_PWD_PasswordExample').contentEditable=true;}
function chuanzhi(){
document.getElementById('mypwd').value = document.getElementById('idDiv_PWD_PasswordExample').innerHTML;
}
</script>
<input id="mypwd" name="mypwd" type="text" value="">
<input type="button" value="传值" onclick="javascript:chuanzhi()">
<div style="cursor:text; border:1px solid #cccccc" class="placeholder" id="idDiv_PWD_PasswordExample">sdfsdf</div>
</body>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询