简体   繁体   English

单击时Div不显示输入或隐藏自身

[英]Div is Not Displaying Input or Hiding Itself When Clicked

I am trying to make a div that hides itself when clicked and shows an input. 我试图制作一个div,它在点击时隐藏自己并显示输入。

My CSS: 我的CSS:

#btn {
    width:100%;
    height:100%;
    display:block;
    text-align:center;
}

#i1 {
    display:none;
}

My JavaScript: 我的JavaScript:

<script>
document.getElementById('btn').onclick = function() {
 document.getElementById('i1').style.display = 'block';
  document.getElementById('btn').style.display = 'none';
}
</script>

My HTML: 我的HTML:

<div id="btn">Company</div><input id="i1" type="text" value="<?php echo"{$row['company']}";}?>">

Can anyone tell me why the Div is not hiding and, or, why the input is not showing? 任何人都可以告诉我为什么Div没有隐藏,或者,为什么输入没有显示?

Thank you for any help. 感谢您的任何帮助。 All help is appreciated. 所有帮助表示赞赏。

The script works perfectly fine here . 该脚本运行完美这里

You're running the script before the element is loaded. 您在加载元素之前运行脚本。 Try placing the <script> at the end of the page. 尝试将<script>放在页面的末尾。

'Your quotes in your php are probably not helping and mess it up some. '你的php中的引用可能没有帮助,搞砸了一些。

Try: 尝试:

<?php

$row['company'] = "some company";
$company = $row['company']

?>

<input id="i1" type="text" value="<?php echo $company?>">

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM