我有一个可折叠的(输入您的信用卡信息)表格。当我点击它时它会打开,但当我点击提交时我希望它关闭。这是我的HTML:
<div class= "addStuff">
<div data-role="collapsible" data-inset="true" id="ccdiv">
<h5> New credit card</h5>
<div data-role="fieldcontain">
<form id = "myForm">
<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">
<button type="button" class="submit" name="submit" value="submit">Submit</button>
</form>
</div>
</div>
这是我的JS尝试:
$(document).ready(function() {
$('.submit').click(function(){
var creditcard = $('#credit_card_number').val();
$('.accounts #CreditCards div[data-role="content"] #swipeMe').append('<li data-swipeurl="#" ><a href="#">' + creditcard + '</a></li>');
// refresh view
$('#CreditCards ul').listview('refresh');
// hide form
alert('test');
$('#myForm').slideUp();
$('#myForm').trigger('collapse');
});
});
答案 0 :(得分:1)
这是一个JsFiddle的链接,我努力尝试让你的代码正常工作 http://jsfiddle.net/rvqRX/
我一行一行地逐一评论每一个,并发现我必须评论的唯一一条行为正确的行是这个
$('#CreditCards ul').listview('refresh');
不确定为什么......对你有意义吗?
答案 1 :(得分:0)
答案 2 :(得分:0)
在表单的submit()上,确保使用JQuery方法调用崩溃表单的触发器。那是你在找什么?