所以,我有一个非常简单的添加和删除图片集。他们目前有单选按钮,让用户选择哪个是默认图片。这是一个简单的html:
<table>
<tr>
<td class="vatop aleft">
<table>
<tr>
<td><div id="pic1" class="picture" ><span>1</span></div></td>
<td><div id="pic2" class="picture" ><span>2</span></div></td>
<td><div id="pic3" class="picture" ><span>3</span></div></td>
<td><div id="pic4" class="picture" ><span>4</span></div></td>
<td><div id="pic5" class="picture" ><span>5</span></div></td>
</tr>
<tr>
<!--JDO 12.12.2013 CWA-9448 -->
<td class="acenter"><input id="default1" type="radio" name="defaultpic" class="defaultpic" picnumber="1" /><span><!--This is where default text go--></span></td>
<td class="acenter"><input id="default2" type="radio" name="defaultpic" class="defaultpic" picnumber="2" disabled="disabled" /><span><!--This is where default text go--></span></td>
<td class="acenter"><input id="default3" type="radio" name="defaultpic" class="defaultpic" picnumber="3" disabled="disabled" /><span><!--This is where default text go--></span></td>
<td class="acenter"><input id="default4" type="radio" name="defaultpic" class="defaultpic" picnumber="4" disabled="disabled" /><span><!--This is where default text go--></span></td>
<td class="acenter"><input id="default5" type="radio" name="defaultpic" class="defaultpic" picnumber="5" disabled="disabled" /><span><!--This is where default text go--></span></td>
<!--END-->
</tr>
<tr>
<td class="aleft vabottom" colspan="5" style="padding-top: 15px;" >
<form id="uploadform" name="uploadForm" method="post" enctype="multipart/form-data" action="FileTransferHandler.ashx" target="pictureframe">
<input id="filepicture" name="filepicture" type="file" class="file" style="margin-right: 5px; width: 450px;" />
<select id="picturenumber" class="" style="margin-right: 5px; width: 80px;"></select>
<input id="uploadpicture" type="submit" value="{{UIT.[147743]}}" class="link" />
<a id="deletepicture" href="javascript:void(0)" rel="deletepicture" class="link" >{{UIT.[8397]}}</a>
</form>
<iframe id="pictureframe" name="pictureframe" src="about:blank" class="hidden"></iframe>
</td>
</tr>
</table>
</td>
</tr>
</table>
现在有了这个我有删除默认图像的问题。例如,我将上传三张图片并选择第二张图片作为默认图片然后删除该图片,图片被删除但是当我的代码选择下一张默认图片(这是第一张图片,因为它有图片)时,它被选中但没有检查单选按钮。请参阅我的代码段以获取删除:
var $deletepicture = $("#main-template #deletepicture");
$deletepicture.click(function () {
$("#main-template #picturenumber option:selected").each(function () {
_picnum = $(this).attr("code");
//Remove the image, show the span, reset the filename attribute of the div
$("#pic" + _picnum.toString() + " img").remove();
$("#pic" + _picnum.toString()).find("span").show();
$("#pic" + _picnum.toString()).removeAttr("filename");
$("#pic" + _picnum.toString()).hide().show();
//Choose another default
$("#default" + _picnum.toString()).removeAttr('checked');
$("#default" + _picnum.toString()).next().text('');
$("#default" + _picnum.toString()).prop('disabled', true);
for (var i = 1; i < 6; i++) {
var $div = $("#pic" + i.toString());
if ($div.attr("filename") !== undefined) {
$("#default" + i.toString()).attr('checked', 'checked');
$("#default" + i.toString()).next().text(' Default');
//JDO 12.12.2013 CWA-9437
return false;
}
};
});
});
我可以看到“默认”从第二张图片移动到第一张图片,但我很难让收看广播框。
答案 0 :(得分:1)
从jQuery 1.9开始,要激活单选按钮,请使用:
$("#default" + i.toString()).prop("checked", true);
而不是
$("#default" + i.toString()).attr('checked', 'checked');