[英]how to end a jquery function on click
我目前使用jQuery slug插件基於標題框創建項目slug。 這非常有效。 我遇到的麻煩只是在用戶點擊編輯鏈接時更新了slug。 現在當調用編輯鏈接時,啟動了slug函數並且工作正常但是當單擊“完成”鏈接時,我需要找到一種方法來關閉slug函數。 我希望這是有道理的。
$('#edit_slug').click(function() {
//allow user to edit the project slug
$("#edit_project_name").stringToSlug({ //this is the slug plugin
getPut: '.project_slug',
hide: false
});
$('input.project_slug').show(); //show the input
$('input.project_slug').next("span").remove().end(); //remove the span with the slug
$('#edit_slug').hide(); //hide edit link
$('input.project_slug').after(" <a href='#' id='done_edit_slug'>Done</a>"); //show done link
});
//if the user is done editing the slug show the span with the slug in it
$('#done_edit_slug').live('click', function() {
$("#edit_project_name").stringToSlug().end(); //my attempt to make the function end
$('input.project_slug').after("<strong><span>"+$('input.project_slug').val()+"</span></strong>"); //show the slug as a span
$('input.project_slug').hide(); //hide the input box
$('#done_edit_slug').remove().end(); //remove done link
$('#edit_slug').show(); //show edit link
});
我不確定這是實現這一目標的最佳方式,我對這些想法持開放態度。 主要的是我不確定在單擊#done_edit_slug
時如何結束stringToSlug()
函數。
謝謝!
在完成事件處理程序中嘗試解除文本框上的事件綁定。
$('#done_edit_slug').live('click', function() {
$("#edit_project_name").unbind("keyup keydown blur");
$('input.project_slug').after("<strong><span>"+$('input.project_slug').val()+"</span></strong>");
$('input.project_slug').hide();
$('#done_edit_slug').remove().end();
$('#edit_slug').show();
});
這是在假設您使用插件源中的默認事件的情況下完成的。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.