jQuery推送img元素
jQuery pushing an img element
我想获取所有表行数据,将它们推送到一个数组中,然后再将它们取回。但目前我只能获得前三列的值,但无法获得图像的src。
我尝试了data.push($(this).val(), $('img').attr('src'));
,但没有成功。
data = [];
$("#car-control-sum tbody>tr").remove();
$("#car-control-table tbody select, #car-control-table tbody input, #car-control-table tbody img").each(function(){
data.push($(this).val());
});
<table data-role="table" id="car-control-table" class="ui-responsive ui-shadow">
<thead>
<tr>
<th style="width:158px;border-bottom: 1px solid #d6d6d6;">Kontrollpunkt</th>
<th style="width:110px;border-bottom: 1px solid #d6d6d6;">OK</th>
<th style="width:158px;border-bottom: 1px solid #d6d6d6;">Kommentar</th>
<th style="width:110px;border-bottom: 1px solid #d6d6d6;">Ta bilde</th>
<th style="width:110px;border-bottom: 1px solid #d6d6d6;">Det.</th>
</tr>
</thead>
<tbody>
<tr class="car-row">
<td>
<select class="select-lys">
<option value="Stotdempere">Stotdempere, fjaerer</option>
</select>
</td>
<td>
<select id="checkup_ok" data-role="slider" style="height:100px;">
<option value=" ">Off</option>
<option value="OK">On</option>
</select>
</td>
<td>
<input style="border: 2px solid #ccc;height:45px;" id="car-control-comment" name="car-control-comment"/>
</td>
<td>
<a style="height:40px;width:40px;margin-bottom:40px;"
class="checkup_cam ui-btn ui-btn-inline ui-btn-icon-notext ui-btn-b ui-corner-all ui-icon-camera"></a>
<img class="checkup_thumb" style="padding-top:10px;"
src="http://www.mountainmansocialmedia.com/_site/wp-content/themes/juiced/img/thumbnail-default.jpg"
height="40" width="40">
</td>
<td>
<a style="height:40px;width:40px;" id="car-control-add"
class="ui-btn ui-btn-inline ui-btn-icon-notext ui-btn-b ui-corner-all ui-icon-plus"></a>
</td>
<td>
</td>
</tr>
</tbody>
</table>
如何将图像src推送到数据数组中
考虑使用.prp()而不是.attr()
var src = $('#image-id').prop('src');
data.push(src);
尝试用this.value
代替$(this).val()
$("#car-control-table tbody select, #car-control-table tbody input, #car-control-table tbody img")
.each(function() {
data.push(this[this.nodeName === "input" ? "value" : "src"])
});
var data = [];
//$("#car-control-sum tbody>tr").remove();
$("#car-control-table tbody select, #car-control-table tbody input, #car-control-table tbody img").each(function() {
data.push(this.value || this.src);
});
console.log(data)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<table data-role="table" id="car-control-table" class="ui-responsive ui-shadow">
<thead>
<tr>
<th style="width:158px;border-bottom: 1px solid #d6d6d6;">Kontrollpunkt</th>
<th style="width:110px;border-bottom: 1px solid #d6d6d6;">OK</th>
<th style="width:158px;border-bottom: 1px solid #d6d6d6;">Kommentar</th>
<th style="width:110px;border-bottom: 1px solid #d6d6d6;">Ta bilde</th>
<th style="width:110px;border-bottom: 1px solid #d6d6d6;">Det.</th>
</tr>
</thead>
<tbody>
<tr class="car-row">
<td>
<select class="select-lys">
<option value="Stotdempere">Stotdempere, fjaerer</option>
</select>
</td>
<td>
<select id="checkup_ok" data-role="slider" style="height:100px;">
<option value=" ">Off</option>
<option value="OK">On</option>
</select>
</td>
<td>
<input style="border: 2px solid #ccc;height:45px;" id="car-control-comment" name="car-control-comment" />
</td>
<td>
<a style="height:40px;width:40px;margin-bottom:40px;" class="checkup_cam ui-btn ui-btn-inline ui-btn-icon-notext ui-btn-b ui-corner-all ui-icon-camera"></a>
<img class="checkup_thumb" style="padding-top:10px;" src="http://www.mountainmansocialmedia.com/_site/wp-content/themes/juiced/img/thumbnail-default.jpg" height="40" width="40">
</td>
<td>
<a style="height:40px;width:40px;" id="car-control-add" class="ui-btn ui-btn-inline ui-btn-icon-notext ui-btn-b ui-corner-all ui-icon-plus"></a>
</td>
<td>
</td>
</tr>
</tbody>
</table>
相关文章:
- 在谷歌地图 API 中,不会为 img 元素触发 Onclick 事件
- angularjs如何找到img元素的高度和宽度
- 为什么可以'tI将IMG元素链接到类似于“;http://en.wikipedia.org/wiki/File:
- 输出表示img元素不存在(为null),但脚本在img的实现下面,并使用了onload()
- 使用带有 img 元素的 css 背景图像
- 将功能元素 IMG 更改为 DIV 背景
- 查找所有嵌套的 img 元素
- 如何访问嵌套在 h1 标签中的 img 标签元素
- 为什么在循环中动态将 .onclick 添加到 img 元素需要返回函数()
- 如何观看 img 元素的 ngSrc 并在自定义指令中获取新的宽度和高度
- 无法将 img 元素换成 SVG
- jquery toggleClass 在 img 元素上不起作用
- 当存在 IMG 元素时,如何设置插入符号位置
- JQuery 查找子元素内部文本并替换为 IMG HTML
- 在元素上单击获取 img src 属性值
- 关于更新Javascript中的img元素类
- 延迟加载图像,但对img元素使用标准语法
- Javascript canvas.toDataUrl()将图片发送到<img>元素
- 如何使用javascript添加img元素
- 元素img上的src属性值不正确:对于动态生成的img src,必须是非空的