javascript單選取得table中一行的數據,並給頁面元素賦值


 

 

<table class="gridtable col-xs-12">
<thead>
<tr>
<th class="col-xs-1">項目</th>
<th class="col-xs-2">內容</th>
<th class="col-xs-1">項目</th>
<th class="col-xs-2">內容</th>
<th class="col-xs-1">項目</th>
<th class="col-xs-2">內容</th>
<th class="col-xs-1">項目</th>
<th class="col-xs-2">內容</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<label asp-for="估價項目房屋信息比較法.房屋編號" class="control-label"></label>
</td>
<td>
<input asp-for="估價項目房屋信息比較法.房屋編號" readonly="readonly" class="form-control" value=@ViewBag.房屋編號 />
<span asp-validation-for="估價項目房屋信息比較法.房屋編號" class="text-danger"></span>
</td>
<td>
<label asp-for="估價項目房屋信息比較法.實例位置" class="control-label"></label>
</td>
<td>
<input asp-for="估價項目房屋信息比較法.實例位置" class="form-control" />
<span asp-validation-for="估價項目房屋信息比較法.實例位置" class="text-danger"></span>
</td>
<td>
<label asp-for="估價項目房屋信息比較法.實例層數" class="control-label"></label>
</td>
<td>
<input asp-for="估價項目房屋信息比較法.實例層數" class="form-control" />
<span asp-validation-for="估價項目房屋信息比較法.實例層數" class="text-danger"></span>
</td>
<td>
<label asp-for="估價項目房屋信息比較法.實例結構" class="control-label"></label>
</td>
<td>
<input asp-for="估價項目房屋信息比較法.實例結構" class="form-control" />
<span asp-validation-for="估價項目房屋信息比較法.實例結構" class="text-danger"></span>
</td>
</tr>
<tr>
<td>
<label asp-for="估價項目房屋信息比較法.實例裝修設施" class="control-label"></label>
</td>
<td>
<input asp-for="估價項目房屋信息比較法.實例裝修設施" class="form-control" />
<span asp-validation-for="估價項目房屋信息比較法.實例裝修設施" class="text-danger"></span>
</td>
<td>
<label asp-for="估價項目房屋信息比較法.實例成交價格" class="control-label"></label>
</td>
<td>
<input asp-for="估價項目房屋信息比較法.實例成交價格" class="form-control" />
<span asp-validation-for="估價項目房屋信息比較法.實例成交價格" class="text-danger"></span>
</td>
<td>
<label asp-for="估價項目房屋信息比較法.實例建築面積" class="control-label"></label>
</td>
<td>
<input asp-for="估價項目房屋信息比較法.實例建築面積" class="form-control" />
<span asp-validation-for="估價項目房屋信息比較法.實例建築面積" class="text-danger"></span>
</td>
<td>
<label asp-for="估價項目房屋信息比較法.實例成交日期" class="control-label"></label>
</td>
<td>
<input asp-for="估價項目房屋信息比較法.實例成交日期" class="form-control" />
<span asp-validation-for="估價項目房屋信息比較法.實例成交日期" class="text-danger"></span>
</td>
</tr>
<tr>
<td>
<label asp-for="估價項目房屋信息比較法.交易情況" class="control-label"></label>
</td>
<td>
<input asp-for="估價項目房屋信息比較法.交易情況" class="form-control" />
<span asp-validation-for="估價項目房屋信息比較法.交易情況" class="text-danger"></span>
</td>
<td>
<label asp-for="估價項目房屋信息比較法.交易日期" class="control-label"></label>
</td>
<td>
<input asp-for="估價項目房屋信息比較法.交易日期" class="form-control" />
<span asp-validation-for="估價項目房屋信息比較法.交易日期" class="text-danger"></span>
</td>
<td>
<label asp-for="估價項目房屋信息比較法.房地產狀況" class="control-label"></label>
</td>
<td>
<input asp-for="估價項目房屋信息比較法.房地產狀況" class="form-control" />
<span asp-validation-for="估價項目房屋信息比較法.房地產狀況" class="text-danger"></span>
</td>
<td>
<label asp-for="估價項目房屋信息比較法.建成年限" class="control-label"></label>
</td>
<td>
<input asp-for="估價項目房屋信息比較法.建成年限" class="form-control" />
<span asp-validation-for="估價項目房屋信息比較法.建成年限" class="text-danger"></span>
</td>
</tr>
<tr>
<td>
<label asp-for="估價項目房屋信息比較法.比准價格成交單價" class="control-label"></label>
</td>
<td>
<input asp-for="估價項目房屋信息比較法.比准價格成交單價" class="form-control" />
<span asp-validation-for="估價項目房屋信息比較法.比准價格成交單價" class="text-danger"></span>
</td>
<td>
<label asp-for="估價項目房屋信息比較法.比准價格區位狀況" class="control-label"></label>
</td>
<td>
<input asp-for="估價項目房屋信息比較法.比准價格區位狀況" class="form-control" />
<span asp-validation-for="估價項目房屋信息比較法.比准價格區位狀況" class="text-danger"></span>
</td>
<td>
<label asp-for="估價項目房屋信息比較法.比准價格實物狀況" class="control-label"></label>
</td>
<td>
<input asp-for="估價項目房屋信息比較法.比准價格實物狀況" class="form-control" />
<span asp-validation-for="估價項目房屋信息比較法.比准價格實物狀況" class="text-danger"></span>
</td>
<td>
<label asp-for="估價項目房屋信息比較法.比准價格交易情況" class="control-label"></label>
</td>
<td>
<input asp-for="估價項目房屋信息比較法.比准價格交易情況" class="form-control" />
<span asp-validation-for="估價項目房屋信息比較法.比准價格交易情況" class="text-danger"></span>
</td>
</tr>
<tr>
<td>
<label asp-for="估價項目房屋信息比較法.比准價格交易日期" class="control-label"></label>
</td>
<td>
<input asp-for="估價項目房屋信息比較法.比准價格交易日期" class="form-control" />
<span asp-validation-for="估價項目房屋信息比較法.比准價格交易日期" class="text-danger"></span>
</td>
<td>
<label asp-for="估價項目房屋信息比較法.比准價格" class="control-label"></label>
</td>
<td>
<input asp-for="估價項目房屋信息比較法.比准價格" class="form-control" />
<span asp-validation-for="估價項目房屋信息比較法.比准價格" class="text-danger"></span>
</td>
</tr>
</tbody>
</table>
<div class="form-group">
<input type="submit" value="Save" class="btn btn-primary" />
</div>
</form>

<script type="text/javascript">

function singleChecked(rowid) {
//存貯所在行的id值
var v = rowid.id;
$("[name='single_checked']").each(function () {
if (this.id != v) {
$(this).removeAttr("checked");//取消選中
}
});

var 實例位置 = $(rowid).parent().parent().children("td").get(2).innerHTML;
var 實例層數 = $(rowid).parent().parent().children("td").get(3).innerHTML;
var 實例總層數 = $(rowid).parent().parent().children("td").get(4).innerHTML;
var 實例結構 = $(rowid).parent().parent().children("td").get(5).innerHTML;
var 實例裝修設施 = $(rowid).parent().parent().children("td").get(6).innerHTML;
var 實例交易情況 = $(rowid).parent().parent().children("td").get(7).innerHTML;

var 實例成交價格 = $(rowid).parent().parent().children("td").get(8).innerHTML;
var 實例建築面積 = $(rowid).parent().parent().children("td").get(9).innerHTML;
var 實例成交單價 = $(rowid).parent().parent().children("td").get(10).innerHTML;
var 實例建成年限 = $(rowid).parent().parent().children("td").get(11).innerHTML;
var 實例成交日期 = $(rowid).parent().parent().children("td").get(12).innerHTML;
var 實例房地產狀況 = $(rowid).parent().parent().children("td").get(13).innerHTML;

$('input[name="估價項目房屋信息比較法.實例位置"]').attr('value', $.trim(實例位置));
$('input[name="估價項目房屋信息比較法.實例層數"]').attr('value', $.trim(實例層數));
$('input[name="估價項目房屋信息比較法.實例結構"]').attr('value', $.trim(實例結構));
$('input[name="估價項目房屋信息比較法.實例裝修設施"]').attr('value', $.trim(實例裝修設施));
$('input[name="估價項目房屋信息比較法.實例成交價格"]').attr('value', $.trim(實例成交價格));
$('input[name="估價項目房屋信息比較法.實例建築面積"]').attr('value', $.trim(實例建築面積));

$('input[name="估價項目房屋信息比較法.實例裝修設施"]').attr('value', $.trim(實例成交日期));
$('input[name="估價項目房屋信息比較法.比准價格成交單價"]').attr('value', $.trim(實例成交價格));
$('input[name="估價項目房屋信息比較法.比准價格區位狀況"]').attr('value', $.trim(實例交易情況));

//$(this).attr("checked", true);
//alert($(this));
}
</script>

<div class="panel-body">

<table class="table table-striped table-bordered table-hover">
<thead>
<tr>
@*<th>

@Html.DisplayNameFor(model => model.編碼比較實例[0].實例名稱)
</th>*@
<th>請選擇實例</th>
<th>
@Html.DisplayNameFor(model => model.編碼比較實例[0].實例名稱)
</th>
<th>
@Html.DisplayNameFor(model => model.編碼比較實例[0].實例位置)
</th>
<th>
@Html.DisplayNameFor(model => model.編碼比較實例[0].實例層數)
</th>
<th>
@Html.DisplayNameFor(model => model.編碼比較實例[0].實例總層數)
</th>
<th>
@Html.DisplayNameFor(model => model.編碼比較實例[0].實例結構)
</th>
<th>
@Html.DisplayNameFor(model => model.編碼比較實例[0].實例裝修設施)
</th>
<th>
@Html.DisplayNameFor(model => model.編碼比較實例[0].實例交易情況)
</th>
<th>
@Html.DisplayNameFor(model => model.編碼比較實例[0].實例成交價格)
</th>
<th>
@Html.DisplayNameFor(model => model.編碼比較實例[0].實例建築面積)
</th>
<th>
@Html.DisplayNameFor(model => model.編碼比較實例[0].實例成交單價)
</th>
<th>
@Html.DisplayNameFor(model => model.編碼比較實例[0].實例建成年限)
</th>
<th>
@Html.DisplayNameFor(model => model.編碼比較實例[0].實例成交日期)

</th>
<th>
@Html.DisplayNameFor(model => model.編碼比較實例[0].實例房地產狀況)
</th>
<th></th>
</tr>
</thead>
<tbody>
@foreach (var item in Model.編碼比較實例)
{
<tr>
<td>
<input id=@Html.DisplayFor(modelItem => item.實例編號) name="single_checked" type="checkbox" onclick="singleChecked(this)" />
</td>
<td>
@Html.DisplayFor(modelItem => item.實例名稱)
</td>
<td>
@Html.DisplayFor(modelItem => item.實例位置)
</td>
<td>
@Html.DisplayFor(modelItem => item.實例層數)
</td>
<td>
@Html.DisplayFor(modelItem => item.實例總層數)
</td>
<td>
@Html.DisplayFor(modelItem => item.實例結構)
</td>
<td>
@Html.DisplayFor(modelItem => item.實例裝修設施)
</td>
<td>
@Html.DisplayFor(modelItem => item.實例交易情況)
</td>
<td>
@Html.DisplayFor(modelItem => item.實例成交價格)
</td>
<td>
@Html.DisplayFor(modelItem => item.實例建築面積)
</td>
<td>
@Html.DisplayFor(modelItem => item.實例成交單價)
</td>
<td>
@Html.DisplayFor(modelItem => item.實例建成年限)
</td>
<td>
@Html.DisplayFor(modelItem => item.實例成交日期)
</td>
<td>
@Html.DisplayFor(modelItem => item.實例房地產狀況)
</td>
<td>
<div class="visible-md visible-lg hidden-sm hidden-xs btn-group">
<button class="btn btn-xs btn-success">
<i class="icon-ok bigger-120"></i>
</button>
<a class="btn btn-xs btn-success" asp-page="./Edit" asp-route-id="@item.實例編號"> <i class="icon-edit bigger-120"></i>編輯</a>
<a class="btn btn-xs btn-info" asp-page="./Details" asp-route-id="@item.實例編號"><i class="icon-flag bigger-120"></i>明細</a>
<a class="btn btn-xs btn-danger" asp-page="./Delete" asp-route-id="@item.實例編號"><i class="icon-trash bigger-120"></i>刪除</a>

</div>

</td>


</tr>
}
</tbody>
</table>


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM