Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/383.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在Jquery属性上使用此类_Javascript_Jquery_Css - Fatal编程技术网

Javascript 在Jquery属性上使用此类

Javascript 在Jquery属性上使用此类,javascript,jquery,css,Javascript,Jquery,Css,这是 HTML 实现的问题在于当前元素上下文不是.ajax完整方法中的phone-email元素 使用 注意:我已经剥离了代码,只保留了所需的部分。您实现的问题是当前元素上下文这不是.ajax完整方法中的phone-email元素 使用 注意:我已经删除了代码,只保留了所需的部分。使用添加一个具有所需样式的类,而不是使用内联样式。have$this.addClass'redborder',在css have.redborder{border:2px solid a94442}中也注意到这个ifo

这是

HTML


实现的问题在于当前元素上下文不是.ajax完整方法中的phone-email元素

使用


注意:我已经剥离了代码,只保留了所需的部分。

您实现的问题是当前元素上下文这不是.ajax完整方法中的phone-email元素

使用


注意:我已经删除了代码,只保留了所需的部分。

使用添加一个具有所需样式的类,而不是使用内联样式。have$this.addClass'redborder',在css have.redborder{border:2px solid a94442}中也注意到这个ifobj.status==0{alertobj.message;$add friend.attr'disabled','disabled';$this.attr'style',border:2px solid a94442';}但是在问题中我想知道如果status=1,那么输入将给出红色边框,你应该澄清这个$this.css'border','2px solid a94442';使用“添加具有所需样式的类”而不是“放置内联样式”。have$this.addClass'redborder',在css have.redborder{border:2px solid a94442}中也注意到这个ifobj.status==0{alertobj.message;$add friend.attr'disabled','disabled';$this.attr'style',border:2px solid a94442';}但是在问题中我想知道如果status=1,那么输入将给出红色边框,你应该澄清这个$this.css'border','2px solid a94442';最好使用CSS类,然后只添加/删除class.dataType:'json'在ajax配置选项和$'add-friend'。prop'disabled'+对象状态_this.toggleClass'error',obj.status=='0';在“完成”回调中。@RezhaVelly,也可以使用tushar建议的“更好”来使用CSS类,然后只添加/删除class.dataType:ajax配置选项中的“json”和$“add-friend”.prop'disabled'+对象状态_this.toggleClass'error',obj.status=='0';在“完成”回调中。@RezhaVelly,也可以使用tushar建议
<div id="myForm" class="myForm row">
    <div class="form-group row">
        <div class="col-lg-12">
            <div class="col-md-4">
                <label>Nama Teman *</label>
                <input type='text' name='name_friend[]' id='name_friend[]' class='form-control name_friend[]' placeholder='Nama' required />
            </div>
            <div class="col-md-4">
                <label>Nomor Handphone*</label>
                <input type='text' name='nomor_telepon[]' id='nomor_telepon[]' class='form-control nomor_telepon[] telepon phone-email' placeholder='Nomor Telepon' required />
            </div>
            <div class="col-md-4">
                <label>Email</label>
                <input type='email' name='email_friend[]' id='email_friend[]' class='form-control email_friend[] phone-email' placeholder='Email' />
            </div>
        </div>
    </div>
    <div class="form-group row">
        <div class="col-lg-12">
            <div class="col-md-4">
                <label>Nama Teman *</label>
                <input type='text' name='name_friend[]' id='name_friend[]' class='form-control name_friend[]' placeholder='Nama' required />
            </div>
            <div class="col-md-4">
                <label>Nomor Handphone *</label>
                <input type='text' name='nomor_telepon[]' id='nomor_telepon[]' class='form-control nomor_telepon[] telepon phone-email' placeholder='Nomor Telepon' required />
            </div>
            <div class="col-md-4">
                <label>Email</label>
                <input type='email' name='email_friend[]' id='email_friend[]' class='form-control email_friend[] phone-email' placeholder='Email' />
            </div>
        </div>
    </div>
</div>
$(".phone-email").blur(function(e) {
    var param = $(this).val();
    var url = "<?php echo base_url('/Campaign/check_data');?>";
    $.ajax({
        url: url,
        type: "POST",
        data: {
            param: param
        }
    }).done(function(d) {
        var obj = JSON.parse(d);
        if (obj.status == "0") {
            alert(obj.message);
            $("#add-friend").attr('disabled', 'disabled');
            $(this).attr('style', 'border: 2px solid #a94442');
        } else if (obj.status == "1") {
            $("#add-friend").removeAttr('disabled');
        }
    });
});
$(this).attr('style', 'border: 2px solid #a94442');
$(".phone-email").blur(function (e) {
    //Cache the this context in a variable
    var _this = $(this); 

    $.ajax().done(function(d){
        //Use the variable
        _this.attr('style', 'border: 2px solid #a94442');

        //You can use .css() method to change the CSS rule
        //_this.css('border', '2px solid #a94442');
    }); 
});