javascript - 无法将事件绑定(bind)到 jquery.steps 向导中的输入

标签 javascript jquery jquery-steps

我正在使用来自 http://www.jquery-steps.com/ 的向导.向导的一切工作都非常顺利,但是当我尝试将事件绑定(bind)到该向导中的输入字段时,它不起作用。以下是该问题的基本代码:

<div class="content">
            <h1>Basic Demo</h1>


            <div id="wizard">
                <h2>First Step</h2>
                <section>
                    <input type="text" class="namer" />

                    <div class="text">This should be replaced</div>

                <h2>Second Step</h2>
                <section>
                    <pdfsgdf</p>
                </section>

            </div>
        </div>

<script>
$(".namer").change(function(e){
  $(".text").html($(this).val()); 
});

$(function ()
                {
                    $("#wizard").steps({
                        headerTag: "h2",
                        bodyTag: "section",
                        transitionEffect: "slideLeft"
                    });
                });

</script>

JSFiddle 位于 http://jsfiddle.net/m23px/

最佳答案

加载向导时,它似乎正在更改事件监听器。您需要改为在 #wizard 上监听事件。

试试这个:

$("#wizard").on('change','.namer',function(){
    $(".text").html($(this).val());     
});

注意:如果您希望更改在用户输入时发生,而不是在字段失去焦点之后,您可以改用 keyup 事件。

$("#wizard").on('keyup','.namer',function(){
    $(".text").html($(this).val());     
});

关于javascript - 无法将事件绑定(bind)到 jquery.steps 向导中的输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20052839/

相关文章:

javascript - 如何在 JavaScript 中访问跨度内的特定文本

javascript - 将类添加到父 div 如果它有一个跨度作为 child

php - 更改 jquery 成功函数的图像?

javascript - 将按钮分配给颜色框

javascript - 在 JQuery Step 中禁用左右键

jquery - 如何使用 jquery-step 在每个步骤中仅验证最多 3 位数字

javascript - Google 跟踪代码管理器包括旧版 Analytics (GA) 和 Universal Analytics (UA) 脚本

javascript 观察者模式在我的代码中提供帮助

javascript - 我可以使用串联的 var+array_value 作为 jquery 中的选择器,即 $ ("#var+array_value")

javascript - JQuery 步骤包装器