在我的rails应用中,我试图允许用户使用#34;标记"表单上的博客文章,通过让用户在类别中键入类别text_field
,当用户按空格键时会分开(这有效!)但是当我去提交页面时,我希望抓取并插入标签回到表单中,这样当页面提交数据时可以正常保存。点击监听器仅在页面立即提交后才执行...
var ready;
ready = function() {
function removeItem(event) {
event.preventDefault();
$(this).parent().remove();
}
$( "#article_article_tags" ).keydown(function(e) {
if(e.keyCode == 32){
var tag = $( "#article_article_tags" ).val();
$("#article-tags").append("<p class='new-tag'>" + tag + "<a class='remove' href='#'> x</a></p>");
$( "#article_article_tags" ).val("")
}
});
$("#article-tags").on('click', '.remove', removeItem)
$('.btn article-submit-button').click(function(event) {
event.preventDefault();
$( "#article_article_tags" ).val($('.new-tag').text());
event.stopPropagation();
});
};
$(document).on('page:change', ready);
答案 0 :(得分:0)
也许您要查找submit
而不是click
事件,然后更改:
$('.btn article-submit-button').click(function(event) {
为:
$('#your_form').submit(function(event) {