单击按钮时添加另一个输入字段

时间:2019-10-23 02:52:48

标签: html forms button input

我做了一些研究,但找不到任何东西。我有一个输入,该人可以在其中输入位置,但是我也希望他们能够添加另一个替代位置。我基本上需要一个按钮来打开表格。这是表格的代码:

<div class="form-group">
    <label for="exampleInputEmail1">Location: </label>
    <input name = "cityForm" class="form-control" placeholder="Enter Zipcode or City" 
        width: 50%;>
</div> 

这是按钮的代码:

<center>
    <button id="locationAlternate" type="submit" class="btn btn-primary">
        Alternate Location
    </button>
</center>

1 个答案:

答案 0 :(得分:0)

这是您要找的吗?

   $('#locationAlternate').on('click',function() {

 $('#location').append('<div class="form-group" id="altloc"><label for="">Alternate Location: </label> <input name = "AltcityForm" class="form-control" placeholder="Enter Alternate Location" width: 50%;></div>');

});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<div class="form-group" id="location">
        <label for="exampleInputEmail1">Location: </label>
        <input name = "cityForm" class="form-control" placeholder="Enter Zipcode or City" width: 50%;>
</div> 

<button id="locationAlternate" type="submit" class="btn btn-primary">Alternate Location</button>