基于中小型单选按钮选择重新调整图像大小:是否可以通过CSS进行调整
Re-size image based on small medium large radio button selection: Is it possible through CSS?
我有一个员工扩展列表表,旁边有员工姓名和员工拇指指甲图像。我需要为用户提供中小型单选按钮(或下拉菜单)选项,并相应地显示员工图像。我想知道这是否可以使用CSS完成?或者,我可以根据单选按钮的选择,用java脚本创建一个CSS类吗?我试图通过java脚本来实现,但它只适用于我的第一行。其余行保持不变。这是我的代码的一瞥。
<Script type="text/javascript">
function changeClass(){
alert(document.getElementById("lastName").getAttribute("style"));
var imgSize = document.getElementById("lastName").getAttribute("style");
if(document.getElementById('ImgSizeSmall').checked == true) {
document.getElementById('lastName').setAttribute("style", "width:75px;" );
} else if(document.getElementById('ImgSizeMedium').checked == true) {
document.getElementById('lastName').setAttribute("style", "width:100px;" );
} else if(document.getElementById('ImgSizeLarge').checked == true) {
document.getElementById('lastName').setAttribute("style", "width:150px;" );
}
</Script>
<Div style="width:385px;height: 950px; float:left; background-color:#A5B3D8;">
<p align="left">
<p align="left"><b>Image Size:</b><br>
<input id="ImgSizeSmall" type="radio" name="ImgSize" value="small" checked="checked" onclick="changeClass()"> <b><i>Small</i></b>
<input id="ImgSizeMedium" type="radio" name="ImgSize" value="medium"> <b><i>Medium</i></b>
<input id="ImgSizeLarge" type="radio" name="ImgSize" value="large"> <b><i>Large</i></b>
</p>
</DIV>
<table id="table_firstname_lastname">
<thead>
<tr>
<th style="width: 208px;">First Name</th>
<th style="width: 208px;">Last Name</th>
<th style="width: 208px;">Phone Number</th>
<th style="width: 275px;">Location</th>
<th style="width: 208px;">Cell</th>
<th style="width: 275px;">Team(s)</th>
</tr>
</thead>
<tbody>
<tr>
<td>first name</td>
<td>last name
<img id="lastName" style="width: 75px;" src="http://imagesource/image.jpg" align="right"></a></td>
<td>9999999999</td>
<td>location 1</td>
<td>8888888888</td>
<td>team name</td>
</tr>
</tbody>
</table>
谢谢,M
我记得CSS技巧中的一篇文章,它导致了Fiddle
HTML:
<div>
<input type="radio" id="tab-1" name="tab-group-1" checked>
<input type="radio" id="tab-2" name="tab-group-1">
<input type="radio" id="tab-3" name="tab-group-1">
<img src="http://www.mycatspace.com/wp-content/uploads/2013/08/adopting-a-cat.jpg"/>
</div>
CSS:
#tab-1[type=radio]:checked ~ img
{
height: 500px;
width: 500px;
}
#tab-2[type=radio]:checked ~ img
{
height: 200px;
width: 200px;
}
#tab-3[type=radio]:checked ~ img
{
height: 50px;
width: 50px;
}
这可能会对你有所帮助。。
我编写了以下java脚本类,很好地解决了我的问题:)
function changeClass(){
var imgSize = document.getElementById("lastName").getAttribute("style");
var table;
if(document.getElementById('radio_firstname_lastname').checked == true) {
table = document.getElementById('table_firstname_lastname');
} else {
table = document.getElementById('table_lastname_firstname');
}
if(document.getElementById('ImgSizeSmall').checked == true) {
for (var r = 1; r < table.rows.length; r++) {
var x = table.rows[r].cells.item(0);
x.getElementsByTagName('img')[0].style.width="75px";
}
} else if(document.getElementById('ImgSizeMedium').checked == true) {
for (var r = 1; r < table.rows.length; r++) {
var x = table.rows[r].cells.item(0);
x.getElementsByTagName('img')[0].style.width="100px";
}
} else if(document.getElementById('ImgSizeLarge').checked == true) {
for (var r = 1; r < table.rows.length; r++) {
var x = table.rows[r].cells.item(0);
x.getElementsByTagName('img')[0].style.width="150px";
}
}
}
相关文章:
- fabric.js:使用 Image.set() 调整图像大小是否会降低图像质量
- 如何检查是否调整浏览器大小的条件
- jquery .width(value) 是否调整容器内图像的大小
- 是否可以调整Adobe Edge动画的大小
- iframe是否可能在没有主窗口帮助的情况下自行调整大小
- Css-是否可以在调整屏幕大小时使元素移动,以使其适合屏幕
- HTML/JavaScript Windows 应用商店应用是否可以在可调整大小的窗口中运行
- 您是否需要“名称.html”来调整EasyXDM iFrame的大小
- 是否有一个JS库可以让我在网格中制作可拖动和可调整大小的磁贴,就像在iPhoto Journal中一样
- 如果用户调整窗口大小/窗口未最大化,是否可以隐藏网页上的图像
- 是否可以根据输入的内容调整文本区域的大小
- 在复杂 DOM 中动态调整框高度是否不高效
- 是否可以调整大小或降低分辨率以减少文件's大小与jquery/js
- 检测元素是否已通过javascript调整大小
- 基于中小型单选按钮选择重新调整图像大小:是否可以通过CSS进行调整
- 是否有一个jQuery/JavaScript函数来调整<0到500>从<0到> 1
- 了解一个元素是否有可能在窗口调整大小时适合另一个元素
- 是否可以访问和控制浏览器的页面大小调整功能?
- 是否有一个jQuery插件或JavaScript代码,以允许客户端大小的图像调整/裁剪在一个圆圈
- 在jQuery中拖动网格时是否可以绑定调整事件大小?可拖动的插件