私信  •  关注

Kiran Shahi

Kiran Shahi 最近创建的主题
Kiran Shahi 最近回复了
5 年前
回复了 Kiran Shahi 创建的主题 » 使用jQuery修改类列表

要在DOM完成加载之后执行代码,以便它可以进行访问或修改,您需要将jQuery代码包装在 $(document).ready(function() {}); . 假设您的代码位于DOM元素之前,例如在标记中,或者在某些DOM元素之前的部分的顶部或中部,并且该代码确实在第一次初始化时尝试访问DOM。

所以它应该放在 $(document).ready() 块,以便在DOM准备好之前它不会执行 $(文档).ready() $(function() {}); 下面是您提供的代码示例。

$(function() {
  $('#colorised').attr('class','table-success');
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<table class="table table-light table-bordered text-center">
    <thead class="thead-dark">
    <tr>
        <th scope="col">Ava</th>
        <th scope="col">Full name</th>
        <th scope="col">Registred</th>
    </tr>
    </thead>
    <tbody>
    {{#users}}
        <tr class="table-light" id="colorised">
            <td><img src="{{avaUrl}}" width="42" height="42"/></td>
            <td><a href="users/{{_id}}" style="margin-top: 50px;">{{username}}</a></td>
            <td>{{registeredAt}}</td>
        </tr>
    {{/users}}
    </tbody>
    {{^users}}
    </br>
    <strong style="color: orange">No results for "{{searchedUsername}}"</strong>
    </br>
    </br>
    {{/users}}
</table>
5 年前
回复了 Kiran Shahi 创建的主题 » jquery:未在动态添加的输入控件上触发keyup事件

自从你 <div class='form-group'><input type='text' class='form-control' id='" + item.id + "' name='textBox'></div> 是一个动态元素。

在追加key-up事件之后,需要将其绑定。例如。

jQuery.each(response.controls, function (index, item) {
    var input = jQuery("<div class='form-group'><input type='text' class='form-control' id='" + item.id + "' name='textBox'></div>");
    jQuery('#fields').append(input);
    inputevent();
});

function inputevent() {
    $('input[type = text]').off('keyup').on('keyup', function (e) {

    });
}
5 年前
回复了 Kiran Shahi 创建的主题 » 添加自动播放到youtube iframe on按钮单击jquery不工作

这可能有效:

<iframe type="text/html" 
    src="https://www.youtube.com/embed/..?autoplay=1" frameborder="0" 
    allow="autoplay">
</iframe>

如果不起作用,请尝试添加 mute=1 muted=1 :

src="https://www.youtube.com/embed/..?autoplay=1&mute=1