Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/444.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中心对齐_Javascript_Center_Alignment - Fatal编程技术网

JavaScript中心对齐

JavaScript中心对齐,javascript,center,alignment,Javascript,Center,Alignment,如何将整个脚本与中心对齐?我以前从未用javascript编写过代码,我只想修改一个快速bookmarklet。我尝试过像align=center这样的方法来处理脚本的不同组件,但没有成功。js有类似于(html)的东西吗 谢谢 编辑:基本上我希望这是一个页面的中心 function dEmbed(){ var iframe = document.createElement("iframe"); iframe.src = 'http://www.google.com';

如何将整个脚本与中心对齐?我以前从未用javascript编写过代码,我只想修改一个快速bookmarklet。我尝试过像align=center这样的方法来处理脚本的不同组件,但没有成功。js有类似于
(html)的东西吗

谢谢

编辑:基本上我希望这是一个页面的中心

function dEmbed(){
    var iframe = document.createElement("iframe");
    iframe.src = 'http://www.google.com';
    iframe.style.width = w+'px';
    iframe.style.height= h+'px';
    iframe.style.border= "0";
    iframe.style.margin= "0";
    iframe.setAttribute("scrolling","no");
    iframe.setAttribute("id","NAME");
    document.body.insertBefore(iframe, document.body.firstChild);
}

你不能将一个脚本居中,它看起来不像任何东西,所以没有任何东西可以居中

如果脚本生成一些HTML,则可以将生成的元素置于中心。这应该使用应用于生成的元素来完成


align
属性过去和现在都不应该使用)。

脚本不能居中,因为它看起来不像任何东西,所以没有任何东西可以居中

如果脚本生成一些HTML,则可以将生成的元素置于中心。这应该使用应用于生成的元素来完成


align
属性过去使用过,现在也不应该使用)。

我可以通过使用
text align:center
将iframe注入现有div来实现这一点


下面是一个示例:

我可以通过使用
文本对齐:居中
将iframe注入现有div来实现这一点

以下是示例:

尝试更改:

iframe.style.margin= "0";
致:

如果不起作用,请在评论中告诉我

好的,请尝试此更改,更改:

var iframe = document.createElement("iframe");
致:

和变化:

document.body.insertBefore(iframe, document.body.firstChild);
致:

尝试更改:

iframe.style.margin= "0";
致:

如果不起作用,请在评论中告诉我

好的,请尝试此更改,更改:

var iframe = document.createElement("iframe");
致:

和变化:

document.body.insertBefore(iframe, document.body.firstChild);
致:


请给我们更多的细节-你的术语都混淆了,很难理解你想要做什么。(特别是请不要像你那样使用文字脚本。)检查我下面编辑的答案,我解决了你的问题。请给我们更多细节-你的术语混淆了,很难理解你想要做什么。(特别是请不要像你那样使用文字脚本。)检查我下面编辑的答案,我解决了你的问题。我昨晚花了大约两个小时来解决这个问题,我无法将它发送到中心。你是否在某处设置了w和h?(宽度和高度?)?我刚刚试过我的代码,只要你设置了这些变量,它就可以正常工作。我昨晚花了两个小时的时间,我没法把它放到中心。你在什么地方设置了w和h吗?(宽度和高度?)?我刚刚试过我的代码,只要设置这些变量,它就可以正常工作。