1

私が書くとき:

var x = window.open('','','width=480,height=500');
x.document.write('
<html>
<head>
<link rel="stylesheet" type="text/css" href="chat.css" / >
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"><' +'/script>
<script type="text/javascript">
alert("hi");
<' + '/script>
</head>
<body><p>hi</p></body>
</html>');

アラートが表示されます。

でももしそうなら--

 x.document.write('
<html>
<head>
<link rel="stylesheet" type="text/css" href="chat.css" / >
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js">
<' +'/script>
<script type="text/javascript">
$(function(){
alert("hi");
});
<' + '/script>
</head>
<body><p>hi</p></body>
</html>');

それからそれは動作しません。それは何もしません。私は一晩中これを理解しようとしてきました。何か案は?

4

1 に答える 1

1

.close()これは、ドキュメントに書き込んだ後に適切にドキュメントを作成しない限り、jQuery が DOM Ready イベントを発生させないためです。

var x = window.open('','','width=480,height=500'),
x.document.write('all your html and script here');
x.document.close();

クレジット: window.open および $(document).ready

于 2012-05-16T05:33:49.647 に答える