我们如何从jquery文件(.js)中调用CSS类.... [英] How we call CSS class from our jquery file(.js)....

查看:126
本文介绍了我们如何从jquery文件(.js)中调用CSS类....的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们如何从我们的.js文件中调用.css文件类
在参加之前





 dev  
{
background-image url(../ Style / Images / valid.png);
background-position 右中心;
background-repeat no-repeat;
}
ashish
{
background- image url(../ Style / Images / invalid.png);
背景-position 右中;
background-repeat no-repeat;
}





 $( function (){

$(' input [type = text]')。每个( function (){
var txt = $( this );
if (txt.val()!= null && txt.val( )!= ' '){
$( this )。removeClass(' ashish');
$( this )。addClass(' dev的');
}
else {
$( this )。removeClass( ' dev');
$( this )。addClass(' 阿希什');
}
})
$(' input [type = text]').focus( function (){
var txt = $( this );
if (txt.val()!= null && txt.val()!= ' '){
$( this )。removeClass(' ashish');
$( this )。addClass(' dev');
}
else {
$( this )。removeClass(' dev');
$( this )。addClass(' ashish' );
}
})
$(' input [type = text]').keyup( function (){
var txt = $( this );
if (txt.val()!= null && txt.val()!= ' '){

$( this )。removeClass(' ashish');
$( this )。addClass(' dev');
}
else {
$ ( this )。removeClass(' dev');
$( this )。addClass(' ashish');
}
})


});





< pre lang =text>当我只在.aspx页面编码时,它的工作正常...但是当我创建.js& .css文件用于我的项目然后我的.js文件无法加载.css类,如(.dev和.ashish)

解决方案

< blockquote>( function (){


' input [type = text]')。each( function (){
var txt =


this );
if (txt.val()!= null && txt.val()!= ' '){


How we can call class of .css file from our .js file
Before attechment



.dev
        {
            background-image: url(../Style/Images/valid.png);
            background-position: right center;
            background-repeat: no-repeat;
        }
        .ashish
        {
            background-image: url(../Style/Images/invalid.png);
            background-position: right center;
            background-repeat: no-repeat;
        }



$(function () {

    $('input[type=text]').each(function () {
        var txt = $(this);
        if (txt.val() != null && txt.val() != '') {
            $(this).removeClass('ashish');
            $(this).addClass('dev');
        }
        else {
            $(this).removeClass('dev');
            $(this).addClass('ashish');
        }
    })
    $('input[type=text]').focus(function () {
        var txt = $(this);
        if (txt.val() != null && txt.val() != '') {
            $(this).removeClass('ashish');
            $(this).addClass('dev');
        }
        else {
            $(this).removeClass('dev');
            $(this).addClass('ashish');
        }
    })
    $('input[type=text]').keyup(function () {
        var txt = $(this);
        if (txt.val() != null && txt.val() != '') {

            $(this).removeClass('ashish');
            $(this).addClass('dev');
        }
        else {
            $(this).removeClass('dev');
            $(this).addClass('ashish');
        }
    })


});



When i m coding this only on .aspx page then its working properly...but when i m creating .js & .css file for using this throught my project then my .js file cant load the .css class like(.dev and .ashish)

解决方案

(function () {


('input[type=text]').each(function () { var txt =


(this); if (txt.val() != null && txt.val() != '') {


这篇关于我们如何从jquery文件(.js)中调用CSS类....的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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