扩展表格和 iframe 的脚本
我有一个脚本可以扩展表格中的 iframe 宽度。该代码之前曾运行过,并且可以在 Internet Explorer 中运行。 javascript 函数是调用展开箭头的 onclick。
这是表代码:
<table cellspacing="0" cellpadding="0" style="border: 1px solid #000000;">
<tbody>
<tr>
<td style="background-color: rgb(232, 226, 210);border-bottom-style: solid;border-right-style:solid;border-width:1px;border-bottom-style:solid;border-width:1px;">
<p class="headings">
iWannaGo.co Best Deals
<a onClick="setContract()" title="Minimise Fares Window">
<img alt="<" width="20" height="20" src="/wp-content/themes/thesis_18/custom/images/left.png"></a>
Expand
<a onClick="setExpand()" title="Maximise Fares Window">
<img alt=">" width="20" height="20" src="/wp-content/themes/thesis_18/custom/images/right.png" >
</a>
</p>
</td>
<td style="background-color: rgb(232, 226, 210);border-bottom-style:solid;border-width:1px;">
<p class="headings">Compare Recommended Sites</p>
</td>
</tr>
<tr>
<td id="fare" style="border-right-style:solid;border-width:1px;vertical-align:top;">
<iframe src="<?php echo $search_fb; ?>" id="farebuzz" scrolling="auto" width=800 height=400 frameborder="0" align="left" style="overflow-x: hidden;padding-left:10px;padding-right:10px;"></iframe>
</td>
<td id="bwix">
<iframe src="<?php echo $search_bw; ?>" id="bwiz" scrolling="auto" width=300 height=300 frameborder="0" style=""> </iframe>
</td>
</tr>
</tbody>
</table>
然后是 javascript 函数。
function setExpand() {
var iframeElement = parent.document.getElementById('farebuzz');
var iframeElements = parent.document.getElementById('bwiz');
var tableElement = document.getElementById('fare');
var tableElements = document.getElementById('bwix');
iframeElement.style.height = 400;
iframeElement.style.width = 960;
iframeElements.style.width=150;
tableElement.style.width=960;
tableElements.style.width=150;
}
function setContract() {
var iframeElement = parent.document.getElementById('farebuzz');
var iframeElements = parent.document.getElementById('bwiz');
var tableElement = document.getElementById('fare');
var tableElements = document.getElementById('bwix');
iframeElement.style.height = 400;
//100px or 100%
iframeElement.style.width = 800;
//100px or 100%
tableElement.style.width=800;
tableElements.style.width=300;
iframeElements.style.width=300;
}
function expanddiv() {
var padElements = document.getElementById('pad');
padElements.style.display='block';
}
这是代码的工作和非工作形式:
链接工作扩展在 IE 中工作,这是什么 真的很混乱。
I have a script that expands an iframe width which is in a table. The code has worked before and works in internet explorer. The javascript function is call onclick of the expand arrow.
This is the table code:
<table cellspacing="0" cellpadding="0" style="border: 1px solid #000000;">
<tbody>
<tr>
<td style="background-color: rgb(232, 226, 210);border-bottom-style: solid;border-right-style:solid;border-width:1px;border-bottom-style:solid;border-width:1px;">
<p class="headings">
iWannaGo.co Best Deals
<a onClick="setContract()" title="Minimise Fares Window">
<img alt="<" width="20" height="20" src="/wp-content/themes/thesis_18/custom/images/left.png"></a>
Expand
<a onClick="setExpand()" title="Maximise Fares Window">
<img alt=">" width="20" height="20" src="/wp-content/themes/thesis_18/custom/images/right.png" >
</a>
</p>
</td>
<td style="background-color: rgb(232, 226, 210);border-bottom-style:solid;border-width:1px;">
<p class="headings">Compare Recommended Sites</p>
</td>
</tr>
<tr>
<td id="fare" style="border-right-style:solid;border-width:1px;vertical-align:top;">
<iframe src="<?php echo $search_fb; ?>" id="farebuzz" scrolling="auto" width=800 height=400 frameborder="0" align="left" style="overflow-x: hidden;padding-left:10px;padding-right:10px;"></iframe>
</td>
<td id="bwix">
<iframe src="<?php echo $search_bw; ?>" id="bwiz" scrolling="auto" width=300 height=300 frameborder="0" style=""> </iframe>
</td>
</tr>
</tbody>
</table>
Then the javascript function.
function setExpand() {
var iframeElement = parent.document.getElementById('farebuzz');
var iframeElements = parent.document.getElementById('bwiz');
var tableElement = document.getElementById('fare');
var tableElements = document.getElementById('bwix');
iframeElement.style.height = 400;
iframeElement.style.width = 960;
iframeElements.style.width=150;
tableElement.style.width=960;
tableElements.style.width=150;
}
function setContract() {
var iframeElement = parent.document.getElementById('farebuzz');
var iframeElements = parent.document.getElementById('bwiz');
var tableElement = document.getElementById('fare');
var tableElements = document.getElementById('bwix');
iframeElement.style.height = 400;
//100px or 100%
iframeElement.style.width = 800;
//100px or 100%
tableElement.style.width=800;
tableElements.style.width=300;
iframeElements.style.width=300;
}
function expanddiv() {
var padElements = document.getElementById('pad');
padElements.style.display='block';
}
Here is a working and not working form of the code:
The link working expansion works in IE which is what is
really confusing.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您不能将
style.width
设置为数字,它必须是字符串,并且必须包含px
后缀:编辑: 另外,请考虑对图像的 alt 属性中的尖括号进行编码。应该是:
这可能不会立即造成问题,但在可预见的将来肯定会造成问题。它已经搞乱了 SO 的代码格式。 :-)
You can't set
style.width
to a number, it has to be a string and it must include thepx
suffix:Edit: Also, consider encoding the angle brackets in your image's alt attribute. It should be:
This may not be causing immediate problems now, but certainly could in the foreseeable future. Already it's messing up SO's code formatting. :-)