Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/446.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 页面刷新后我的div元素消失帮助我 函数create() { var div=document.createElement('div'); div.textContent=document.getElementById('text')。值; div.setAttribute('class','note'); 文件.正文.附件(div); div.style.background=“黄色”; div.style.Width=“300px”; div.style.height=“100px”; if(document.getElementById('text')。值=“”) { div.parentNode.removeChild(div); 警报(“请放一些文字”); } }_Javascript - Fatal编程技术网

Javascript 页面刷新后我的div元素消失帮助我 函数create() { var div=document.createElement('div'); div.textContent=document.getElementById('text')。值; div.setAttribute('class','note'); 文件.正文.附件(div); div.style.background=“黄色”; div.style.Width=“300px”; div.style.height=“100px”; if(document.getElementById('text')。值=“”) { div.parentNode.removeChild(div); 警报(“请放一些文字”); } }

Javascript 页面刷新后我的div元素消失帮助我 函数create() { var div=document.createElement('div'); div.textContent=document.getElementById('text')。值; div.setAttribute('class','note'); 文件.正文.附件(div); div.style.background=“黄色”; div.style.Width=“300px”; div.style.height=“100px”; if(document.getElementById('text')。值=“”) { div.parentNode.removeChild(div); 警报(“请放一些文字”); } },javascript,Javascript,问题可能在这一行 <script> function create() { var div = document.createElement('div'); div.textContent = document.getElementById('text').value; div.setAttribute('class', 'note'); document.body.appendChild(div); div.style.back

问题可能在这一行

<script>

function create()

{

    var div = document.createElement('div');

    div.textContent = document.getElementById('text').value;

    div.setAttribute('class', 'note');

    document.body.appendChild(div);

    div.style.background="yellow";

    div.style.Width="300px";

    div.style.height="100px";

    if(document.getElementById('text').value=="")

    {
        div.parentNode.removeChild(div);

        alert("Plz Put Some text");
    }
}

</script>

<body>

<input type="button" onclick="create()" value="create"/>

<input type="text" id="text" />

</body>
但是您没有给id=“text”赋予任何值


试试这个<代码>

每次加载页面时,您都会得到一份新的副本。如果刷新,则不会保存对DOM所做的更改。
<input type="text" id="text" />
if(document.getElementById('text').value=="")