jQuery:tagsInput 重新初始化(或取消绑定(bind)所有内容)

标签 jquery

我有一个标记插件( http://xoxco.com/projects/code/tagsinput/ ),唯一的问题是,我经常将内容加载到同一个 DOM 中 - 因此 .tagsInput() 再次被调用。问题是,当它多次发生时,插件将无法工作 - 所以首先我需要以某种方式解除它的绑定(bind),但没有内部方法......

最佳答案

您没有提供太多上下文,但如果您想绑定(bind)和取消绑定(bind),请查看 jQuery 上的 on()off():

<!DOCTYPE html>
<html>
<head>
  <style>
button { margin:5px; }
button#theone { color:red; background:yellow; }
</style>
  <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
</head>
<body>
  <button id="theone">Does nothing...</button>
<button id="bind">Add Click</button>
<button id="unbind">Remove Click</button>
<div style="display:none;">Click!</div>
<script>
function aClick() {
  $("div").show().fadeOut("slow");
}
$("#bind").click(function () {
  $("body").on("click", "#theone", aClick)
    .find("#theone").text("Can Click!");
});
$("#unbind").click(function () {
  $("body").off("click", "#theone", aClick)
    .find("#theone").text("Does nothing...");
});
</script>

</body>
</html>

这是demo

关于jQuery:tagsInput 重新初始化(或取消绑定(bind)所有内容),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17202922/

相关文章:

jquery - 按键事件不起作用

php - 自定义 Wordpress 登录对齐以居中 CSS

javascript - jQuery :checked getting value of last element

jquery - 使用 Rails 中的下拉菜单和 Jquery 重定向到编辑路径

javascript - 获取HTML页面中所有 `position:fixed`的元素?

javascript - jQuery UI 设计模式问题

javascript - 单击或触摸时切换 div,并在单击/触摸外部时隐藏

jquery - 如何通过向左/向右/顶部/底部滑动来移动 div? (jquery)

javascript - 为什么 ajax 调用没有按指定的延迟进行

jquery - 当用户使用 jQuery 将表头滚动到 View 之外时,表头保持固定在顶部