我有一个可折叠的表格,要求提供信用卡信息。当有人点击提交时,我希望将卡号移到另一个列表中。我如何使用Javascript执行此操作。这是我的HTML:
<div class= "addStuff">
<div data-role="collapsible" data-inset="true" >
<h5> New credit card</h5>
<div data-role="fieldcontain">
<input type="password" name="credit_card_number" id="credit_card_number" value="" placeholder="Credit Card Number">
<input type="password" name="security_code" id="security_code" value="" placeholder="Security Code">
<input type="date" name="expiration_date" id="expiration_date" value="" placeholder="Expiration Date">
<input type="password" name="name" id="name" value="" placeholder="Name On Card">
<input type="password" name="street_address" id="street_address" value="" placeholder="Street Address">
<input type="text" name="city" id="city" value="" placeholder="City">
<input type="number" name="zip_code" id="zip_code" value="" placeholder="Zip Code">
<form action="accounts.html" method="post">
<button type="submit" class="submit" name="submit" value="submit" data-theme="">Submit</button>
</form>
</div>
</div>
</div>
以下是我要将其添加到的列表:
<div class="accounts">
<h2>Existing Acounts </h2>
<ul data-role="listview" >
<div id= "Credit Cards">
<li><a href="AccountDetails.html">BofA Enhcanced Checking 3212</a></li>
<li><a href="AccountDetails.html">BankAmericard Platinum Plus Visa 4567</a></li>
<li><a href="AccountDetails.html">CITI Platinum 4331</a></li>
</div>
</ul>
<ul data-role="listview" >
<div id= "Accounts">
<li><a href="AccountDetails.html">Bank of America Checking</a></li>
<li><a href="AccountDetails.html">Bank of America Savings</a></li>
</div>
</ul>
这是我的尝试:
$('document').ready(function() {
$('.addStuff .submit').click(function(){
$('#credit_card_number').addClass('.accounts' )
});
});
答案 0 :(得分:1)
将提交按钮更改为按钮:
<button type="button" class="submit" name="submit" value="submit">Submit</button>`
更新的javascript是:
$('document').ready(function() {
$('.submit').click(function(){
var creditcard = $('#credit_card_number').val();
$("#CreditCards ul").append('<li><a href="AccountDetails.html">' +
creditcard + "</a></li>");
// refresh view
$('#CreditCards ul').listview('refresh');
// hide form
$('#ccdiv').trigger('collapse');
});
});
答案 1 :(得分:0)
您可以使用以下内容:
$('document').ready(function() {
$('#oldForm .submit').click(function(){
var option = $("#oldSelect option:selected");
$("#newSelect").append('<option value='+option.val()+'>'+option.html()+'</option>');
});
});
答案 2 :(得分:0)
列出您的清单,例如:
<ul id="creditcards">
</ul>
在点击按钮时,通过jquery将credit_card_number输入的值附加到列表中:
$('document').ready(function() {
$('.submit').click(function(){
$("#creditcards").append("<li>"+$("#credit_card_number").val()+"</li>");
});
});
小提琴: