日期:2014-05-16 浏览次数:20685 次
<html>
<head>
<script type="text/javascript" src="jquery-1.3.2.js"></script>
<script type="text/javascript">
$(function() {
$('#c').click(function() {
$('body').append(
$('<div style="width: 500px; height: 300px;">').append(
$('<iframe src="http://www.baidu.com" style="width: 500px; height: 300px;">')
)
);
});
$('body').append(
$('<div style="width: 500px; height: 300px;">').append(
$('<iframe src="http://www.baidu.com" style="width: 500px; height: 300px;">')
)
);
});
</script>
</head>
<body>
<input type="button" value="click" id="c" />
</body>
</html>
------解决方案--------------------
以下代码在IE6, 7, 8, chrome, firefox, opera下都测试通过
<html>
<head>
<script type="text/javascript" src="jquery-1.3.2.js"></script>
<script type="text/javascript">
function createIframe4Standard() {
var wrapper = document.createElement('div');
var iframe = document.createElement('iframe');
wrapper.style.setProperty('width', '500px', 1);
wrapper.style.setProperty('height', '300px', 1);
iframe.style.setProperty('width', '500px', 1);
iframe.style.setProperty('height', '300px', 1);
iframe.setAttribute('src', 'http://www.baidu.com');
wrapper.appendChild(iframe);
return wrapper;
}
function createIframe4Ie() {
var wrapper = document.createElement('div');
var iframe = document.createElement('iframe');
wrapper.style.width = '500px';
wrapper.style.height = '300px';
iframe.style.width = '500px';
iframe.style.height = '300px';
iframe.src = 'http://www.baidu.com';
wrapper.appendChild(iframe);
return wrapper;
}
function createIframe() {
return document.all ? createIframe4Ie() : createIframe4Standard();
}
$(function() {
$('#c').click(function() {