我已经尝试过以下方式。这很好,可以动态地将隐藏输入添加到表单中。但是如何在控制器操作中使用隐藏输入字段,以便我将做进一步的工作,即在浏览器中呈现动态添加的图像。
JQuery 追加方法:
<script type="text/javascript">
var alts = "";
var n = 65;
$(document).ready(function () {
$(function () {
$("#selectable_images img").click(function () {
var $this = $(this);
// alts = $(this).attr("alt");
// alert(alts);
if ($this.hasClass('selected')) {
$("#" + this.rel).attr('checked', false);
$this.removeClass('selected');
// $("#postform").remove("");
//$("input[type='hidden']").remove();
//$('input[type="hidden"][value="' + alts + '"]').remove();
alts = $(this).attr("alt");
var ref = "#";
ref += alts.toString();
alert(ref);
$(ref).remove();
} else {
$("#" + this.rel).attr('checked', true);
$this.addClass('selected');
alts = $(this).attr("alt");
alert(alts);
charPos++;
$("#postform").append("<input type='hidden' id='" + alts.toString() + "' value='" + n.toString() + "'/>");
n++;
}
})
})
});
</script>
图片标签:
<div class="selected" id="selectable_images">
<table>
<tr>
<td>
<img src="../../Images/wi0096-48.gif" alt="Image1" class="conversation_img"/>
</td>
<td>
<img src="../../Images/down.png" alt ="image1"/>
</td>
<td>
<img src="../../Images/wi0054-48.gif" alt="Image2" />
</td>
<td>
<img src="../../Images/Photo-icon.png" alt="image3" />
</td>
</div>
形式:
@using (Html.BeginForm("MapIcon","test", FormMethod.Post,new { id = "postform" }))
{
<input type="submit" value="Match"/>
}