Javascript 如果在jquery中没有警报函数,则单击函数不起作用

Javascript 如果在jquery中没有警报函数,则单击函数不起作用,javascript,jquery,angularjs,media-queries,Javascript,Jquery,Angularjs,Media Queries,我已经使用ng repeat创建了一个预览播放列表,但预览图像上的单击功能无法正常工作。 以下是我的HTML代码: <div class="imgBox" ng-repeat="playlist in channelItems.slice(0,5)" ng-click="onPreviewClick($index)" id="imgFB{{$index}}"> <img id="preview" class="imgthumbnew

我已经使用ng repeat创建了一个预览播放列表,但预览图像上的单击功能无法正常工作。 以下是我的HTML代码:

   <div class="imgBox" ng-repeat="playlist in channelItems.slice(0,5)" ng-click="onPreviewClick($index)" id="imgFB{{$index}}">
                    <img id="preview" class="imgthumbnew" ng-src="{{playlist.ImageURL}}" data-item="{{playlist.MediaUrl}}" />
                    <span>
                        <label style="font-size: 12px; ">{{playlist.Title}}</label>
                    </span>
                </div>

首先,像这样使用angularjs和jQuery的方法是不正确的,请使用正确的ng click处理程序来注册您的click处理程序

<div class="imgBox" ng-repeat="playlist in channelItems.slice(0,5)" ng-click="onPreviewClick($index)" id="imgFB{{$index}}">
    <img id="preview" class="imgthumbnew" ng-src="{{playlist.ImageURL}}" ng-click="imgthumbnewclick()" />
    <span>
        <label style="font-size: 12px; ">{{playlist.Title}}</label>
    </span>
</div>

另一种解决方案是使用事件委派来支持动态元素

jQuery(function ($) {
    $(document).on('click', '.imgthumbnew', function () {
        $("#mediaPlayerDiv").show();
        $("#thumbnail").hide();
        $("#media-video").attr({
            "src": $(this).data("item"),
                "autoplay": "autoplay",
            //"data-tag": "true"
        })
    })
});

首先,像这样使用angularjs和jQuery的方法是不正确的,请使用正确的ng click处理程序来注册您的click处理程序

<div class="imgBox" ng-repeat="playlist in channelItems.slice(0,5)" ng-click="onPreviewClick($index)" id="imgFB{{$index}}">
    <img id="preview" class="imgthumbnew" ng-src="{{playlist.ImageURL}}" ng-click="imgthumbnewclick()" />
    <span>
        <label style="font-size: 12px; ">{{playlist.Title}}</label>
    </span>
</div>

另一种解决方案是使用事件委派来支持动态元素

jQuery(function ($) {
    $(document).on('click', '.imgthumbnew', function () {
        $("#mediaPlayerDiv").show();
        $("#thumbnail").hide();
        $("#media-video").attr({
            "src": $(this).data("item"),
                "autoplay": "autoplay",
            //"data-tag": "true"
        })
    })
});

检查DOM元素的范围。不管这是否在范围内,问题在于ajax请求时间,@arun p Johny已经解决了。检查DOM元素的范围。不管这是否在范围内,问题在于ajax请求时间,@arun p Johny已经解决了。很抱歉,它根本不起作用,我已经尝试过了。问题不在于“ID”或“CLASS”@arun p Johny回答得很好很抱歉根本不起作用,我已经试过了。问题不在于“ID”或“CLASS”@阿伦·p·约翰尼回答得很好
// you can call click event on id easily 
$(document).ready(function () {
        //alert("clicked");
        setTimeout(function () {
        $("#preview).click(function () { // use this line
        //$(".imgthumbnew").click(function () {
            $("#mediaPlayerDiv").show();
            $("#thumbnail").hide();
            $("#media-video").attr({
                "src": $(this).data("item"),
                "autoplay": "autoplay",
                //"data-tag": "true"
            })
        })
        }, 500);
 });