在Javascript中创建Div显示块 [英] Make Div display block in Javascript

查看:86
本文介绍了在Javascript中创建Div显示块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的所有人,



我想在javascript中制作div元素显示块。当使用location.href时,div内容会立即消失。



以下是我的javascript函数:



 function TestOne1(){
window.location.href = ../ Test.aspx文件的一个=了Numberone?;
document.getElementById( divSub1)。style.display = ' ';
}





即使在使用window.location.href更改URL后,如何显示div内容。





任何帮助或建议都将不胜感激。



谢谢,

解决方案

所以你试图显示一个div,但是因为你正在更改URL,所以DOM会刷新并且你的div正在消失,然后才真正看到它吗? br />


尝试在导航到新URL之前几秒更改div,如下所示:

 < span class =code-keyword> function  TestOne1(){
document .getElementById( divSub1)。style.display = ' 块';
setTimeout( function (){ window location .href = ../ Test.aspx?One = numberone;} , 3000 );
}





这样,div就会显示,三秒钟之后,页面就会导航。


 history.pushState(null,null,'.. / Test.aspx?One = numberone') ;


Dear All,

I am trying to make div element display block in javascript. When using location.href, the div content comes and disappears immediately.

Following is my javascript function :

function TestOne1() {
            window.location.href = "../Test.aspx?One=numberone";
            document.getElementById("divSub1").style.display = '';            
        }



How do I display the div content even after changing my URL using window.location.href.


Any help or suggestion would be greatly appreciated.

Thanks,

解决方案

So you're trying to display a div, but because you are changing the URL, the DOM is refreshing and your div is disappearing before you can really see it?

Try changing the div a few seconds before you navigate to the new URL, like this:

function TestOne1() {
    document.getElementById("divSub1").style.display = 'block';
    setTimeout(function() { window.location.href = "../Test.aspx?One=numberone"; }, 3000); 
}



This way, the div will be displayed, and three seconds later, the page will navigate.


history.pushState(null, null, '../Test.aspx?One=numberone');


这篇关于在Javascript中创建Div显示块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆