Javascript 使用复选框自动更新字段
在我的MVC项目中,当客户创建帐户时,会提示他们输入发票地址和发货地址 我希望在发票地址下方有一个复选框,它将使用相同的发票地址详细信息更新发货地址,而不是必须输入相同的地址两次 不知道如何做,任何帮助将不胜感激)复选框的一个例子是Javascript 使用复选框自动更新字段,javascript,jquery,asp.net-mvc,Javascript,Jquery,Asp.net Mvc,在我的MVC项目中,当客户创建帐户时,会提示他们输入发票地址和发货地址 我希望在发票地址下方有一个复选框,它将使用相同的发票地址详细信息更新发货地址,而不是必须输入相同的地址两次 不知道如何做,任何帮助将不胜感激)复选框的一个例子是 <div class="checkbox">@Html.CheckBoxFor(m => signup.SameAddress)</div> <div class="label">@Html.LabelFor(m =>
<div class="checkbox">@Html.CheckBoxFor(m => signup.SameAddress)</div>
<div class="label">@Html.LabelFor(m => signup.SameAddress, T(Use same address as billing"))</div>
@Html.CheckBoxFor(m=>signup.SameAddress)
@LabelFor(m=>signup.SameAddress,T(使用与账单相同的地址)
到目前为止,我的代码如下所示。他们必须输入相同的详细信息两次
<article class="addresses form">
<fieldset>
<div class="span5">
<h2>@T("Invoice Address")</h2>
<table class="table-bordered table-striped table">
<colgroup>
<col id="Col1" />
<col id="Col2" />
</colgroup>
<thead>
<tr>
<th scope="col">@T("Name")</th>
<td>@invoiceAddress.Name.Value</td>
</tr>
<tr>
<th scope="col">@T("AddressLine1")</th>
<td>@invoiceAddress.AddressLine1.Value<</td>
</tr>
</thead>
</table>
</div>
//insert checkbox here
<div class="span5">
<h2>@T("Billing Address")</h2>
<table class="table-bordered table-striped table">
<colgroup>
<col id="Col1" />
<col id="Col2" />
</colgroup>
<thead>
<tr>
<th scope="col">@T("Name")</th>
<td>@shippingAddress.Name.Value</td>
</tr>
<tr>
<th scope="col">@T("AddressLine1")</th>
<td>@shippingAddress.AddressLine1.Value<</td>
</tr>
</thead>
</table>
</div>
</fieldset>
</article>
@T(“发票地址”)
@T(“名称”)
@invoiceAddress.Name.Value
@T(“地址行1”)
@invoiceAddress.AddressLine1.Value您需要一些东西来标识您的列,我在这里使用了带有ID的输入标记,我可以在上面选择
<input type="checkbox" id="test3"/>
<label for="test1">Invoice address</label><input id="test1" type="text"/>
<label for="test2">Shipping address</label><input id="test2" type="text"/>
$("#test1").on("change", function () {
if ($("#test3").is(":checked"))
$("#test2").val($(this).val()) ;
});
发票地址
送货地址
$(“#test1”)。关于(“更改”,函数(){
如果($(“#test3”)。为(“:选中”))
$(“#test2”).val($(this.val());
});