【问题标题】:.live works when it shouldn't, and .bind doesn't work where it should.live 在不应该工作的地方工作,而 .bind 在应该工作的地方工作
【发布时间】:2011-05-27 14:55:47
【问题描述】:

我在现有的 DOM 元素上使用它:

function questionsForm() {
    $("form[name='qc']:last").bind("focus", newTextLine);
}

它不起作用,但是当我用 .live 替换 .bind 时它起作用了 这是句柄应该工作的 HTML:

    <body>

    <div id="screen">
        <div id="form">
            <div id="insertQuestions">
                <form id="qc" name="qc">
                <h2>Create New Question!</h2>
                <div id="question">Question: <input type="text" name="Question" /></div><!--question-->
                <input type="submit" value="Submit" />

为什么会这样? jQuery 1.6

【问题讨论】:

  • jQuery 1.6,更多字符发布问题.. :)

标签: jquery bind live


【解决方案1】:

bind 仅添加事件处理程序。 trigger 运行它。

live 都添加处理程序并运行它

旁注

你为什么不直接选择表单的 ID?

$("form#qc").bind("focus", newTextLine);

【讨论】:

  • 他们的使用描述相同:$('selector').bind/.live("event", function)
  • @IlyaD 你的来源是什么?
  • @Neal,jQuery 文档:api.jquery.com/bindapi.jquery.com/live
  • 我在bind 的文档中没有看到任何关于live 的内容
  • @Neal,也许我理解错了,但你说我需要使用名为 trigger 的东西,而我在文档中什么也没看到,似乎 live 和 @ 的使用模式987654332@ 完全一样,还是我错了?并感谢 ID 提示
猜你喜欢
  • 2021-01-27
  • 1970-01-01
  • 2022-11-14
  • 1970-01-01
  • 2015-03-31
  • 1970-01-01
  • 1970-01-01
  • 2021-06-09
  • 1970-01-01
相关资源
最近更新 更多