簡體   English   中英

復選框填充表單字段

[英]Checkbox Populate Form Fields

我希望使用復選框來填充表單字段。

用戶流程示例:
訪客填寫運輸信息字段,例如名稱,地址,郵政編碼,城市。
訪客可以選擇復選框以自動填充帳單信息字段。
如果用戶選中“與帳單信息相同”復選框,則貨運信息字段
輸入的數據將被復制/粘貼到帳單信息字段中。

請訪問: http//staelements.com/register

動態填充復選框自動表單復制粘貼字段

J $是實現這一目標的最佳方法嗎?
請告訴我是否有更好的解決方案。
感謝您的關注,好公民!

您可以使用Jquery實現此目標。首先將適當的jquery庫加載到您的項目或頁面中。

那么如果您的復選框是這樣的

<input type="checkbox" id="checkbox1" />

<!-- account form fields  -->
<input type="text" id="name" />
<input type="text" id="phone" />

<!-- billing form fields-->
<input type="text" id="name_billing" />
<input type="text" id="phone_billing" />

$(document).ready(function(){
 $("#checkbox1").change(function() {
  if(this.checked) {
   alert("checked ");
    //get the values of the filled fields
    $name = $("#name").val();
    $phone = $("#phone").val();
    console.log("name");
    // then add those values to your billing infor window feilds 

    $("#name_billing").val($name);
    $("#phone_billing").val($phone);

    // then form will be automatically filled .. 

  }
  else{
   $('#name_billing').val('');
   $("#phone_billing").val('');
  }
 });
});

檢查js小提琴http://jsfiddle.net/2kt0usfx/

如果要在取消選中時刪除值,則

我沒有對此進行測試,但希望這對您有用

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM