使用jQuery在HTML内插入变量值 [英] Insert variable value inside html with jQuery

查看:280
本文介绍了使用jQuery在HTML内插入变量值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用jQuery在HTML内插入名称变量的值(在数据对象内部)?

Hi how do you insert the value of the name variable (inside the data object) inside html using jQuery?

可以用jQuery实现吗? 我的代码:

Can you achieve this with jQuery? My code:

data = { // data object
    action: 'addMember',
    managerPassword: App.manager,
    name: $('#name_add').attr('value'),
    email: $('#email_add').attr('value')
};

$.ajax({
    url: App.URL_manager,
    data: data,
    dataType: 'json',
    type: 'POST',
    success: function(r) {
        if (r.success) {
            $('.add_staff').fadeOut(1000, function() {
                $('.success').find('#name').([INSERT VARIABLE HERE]);
                $('.success').fadeIn(1000);
            })
        }
        else {
            alert('you looser');
        }
    }
});​

推荐答案

只需使用.引用对象数据,就可以像data.name一样进行操作:

Just use the . to refer object data, You do it like data.name:

success: function(r){
    if (r.success) {
        $('.add_staff').fadeOut(1000, function(){
            $('.success').find('#name').html(data.name);
        $('.success').fadeIn(1000);
        })
}

这篇关于使用jQuery在HTML内插入变量值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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