.blur()事件不会激活,选择器有两个类名

Sat*_*ngh 0 javascript jquery

示例DEMO中, 我希望在类.drow1 .subval失去焦点时触发事件,可能会遗漏某些东西,

JS:

$(".drow1 .sub_val").on('blur',funtion(){
alert("hello");
});
Run Code Online (Sandbox Code Playgroud)

HTML:

<table border="1">
    <tr>
        <th>Col 1</th>
        <th>Col 2</th>
        <th>Type</th>
    </tr>
    <tr>
        <td> one</td>
        <td>
            <input type="text" value="600" class="sub_val" />
        </td>
        <td>dummy text</td>
    </tr>

    <tr class="drow1">
        <td> Two</td>
        <td>
            <input type="text" value="50" class="sub_val" />
        </td>
        <td>drow1</td>
    </tr>

    <tr class="drow1">
        <td> Three</td>
        <td>
            <input type="text" value="30" class="sub_val" />
        </td>
        <td>drow1</td>
    </tr>
     <tr class="drow2">
        <td> Four</td>
        <td>
            <input type="text" value="30" class="sub_val" />
        </td>
        <td>drow 2</td>
    </tr>
</table>
Run Code Online (Sandbox Code Playgroud)

编辑:具有类的表行.drow1是动态创建的,因此它不会起火

und*_*ned 6

你的代码中有一个拼写错误,funtion应该是function:

$(".drow1 .sub_val").on('blur',function(){
   alert("hello");
});
Run Code Online (Sandbox Code Playgroud)

编辑:如果要动态创建元素,则应委派事件:

$("table").on("blur", ".sub_val", function() {
    alert("hello");
});
Run Code Online (Sandbox Code Playgroud)