如何在JavaScript onclick函数中运行jQuery代码? [英] How to run jQuery code in the JavaScript onclick function?

查看:78
本文介绍了如何在JavaScript onclick函数中运行jQuery代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

单击关闭" anchor不会关闭通知.

Clicking on the "close" anchor does not close the notification.

下面是我的代码:

function show_notification_on_top(message, type) {  

    content =   "<a class='notify-close' onclick='$(\"#notification-box\").fadeOut(\"slow\");' href='#'>close</a>"+ 
                "<p>"+message+"</p>";                   

    $("#notification-box").fadeIn('slow', function() {
            $("#notification-box").delay(60000).fadeOut('slow');
        });

    $("#notification-box").html( content ); 
}

推荐答案

不要在<a>链接上硬编码onclick事件,请使用JQuery click不干扰订阅者.

Don't hardcode onclick events on <a>links, use JQuery click unobtrusive subscriber.

function show_notification_on_top(message, type) {  

    content =           
                "<a class='notify-close' href='#'>close</a>"+
                "<p> message </p>";                   

    $("#notification-box").fadeIn('slow', function() {
            $("#notification-box").delay(60000).fadeOut('slow');
        });

    $("#notification-box").html( content ); 

    $('.notify-close').click(function(){
            $('#notification-box').dequeue();
        });
}

这篇关于如何在JavaScript onclick函数中运行jQuery代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆