Tôi có dạng hộp thoại sau:Twitter Bootstrap 2 phương thức dưới dạng các hộp thoại
<div class='modal' id='myModal'>
<div class='modal-header'>
<a class='close' data-dismiss='modal'>×</a>
<h3>Add Tags</h3>
</div>
<div class='modal-body'>
<form accept-charset="UTF-8" action="/tagging" data-remote="true" method="post"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="✓" /><input name="authenticity_token" type="hidden" value="mCNvbvoPFWhD7SoJm9FPDh+BcRvCG3d16P+oOFACPuc=" /></div>
<input id="tags_string" name="tags_string" type="text" value="luca" />
<input id="id" name="id" type="hidden" value="4f1c95fd1d41c80ff200067f" />
</form>
</div>
<div class='modal-footer'>
<div class='btn btn-primary'><input name="commit" type="submit" value="Add tag" /></div>
</div>
</div>
và JS của mình:
<script>
//<![CDATA[
$(function() {
// wire up the buttons to dismiss the modal when shown
$("#myModal").bind("show", function() {
$("#myModal a.btn").click(function(e) {
// do something based on which button was clicked
// we just log the contents of the link element for demo purposes
console.log("button pressed: "+$(this).html());
// hide the dialog box
$("#myModal").modal('hide');
});
});
// remove the event listeners when the dialog is hidden
$("#myModal").bind("hide", function() {
// remove event listeners on the buttons
$("#myModal a.btn").unbind();
});
// finally, wire up the actual modal functionality and show the dialog
$("#myModal").modal({
"backdrop" : "static",
"keyboard" : true,
"show" : true // this parameter ensures the modal is shown immediately
});
});
//]]>
</script>
Khi tôi bấm x, đó là <a class='close' data-dismiss='modal'>×</a>
, hình thức đóng cửa để lại cho tôi trên trang hiện tại, trong khi tôi muốn đi trên hamepage.
Ngoài ra "Thêm thẻ" botton, là <div class='btn btn-primary'><input name="commit" type="submit" value="Add tag" /></div>
không làm gì cả, trong khi nhấp vào jaust ENTER trên bàn phím thực hiện công việc và tôi muốn nhấp vào "Thêm thẻ" đã thực hiện tương tự.
Tôi không quá giỏi về JS và prog front-end, vì vậy mọi trợ giúp đều được chào đón.
Rất may, [Bootstrap 2.0.2 giới thiệu 'modal-form' lớp] (https://github.com/twitter/bootstrap/issues/2218) để sửa lỗi này bằng cách cho phép bạn bọc 'modal-header/modal-body/modal-footer' trong thẻ' form', như bạn mong đợi! Xem [câu trả lời này] (http://stackoverflow.com/a/10893506/200322) để biết thêm chi tiết. – TheCloudlessSky
@ TheCloudlessSky cảm ơn bạn đã nâng cấp –