解决方案 »

  1.   


    $('#slbutton').on('click',function(){
    $(this).css({background:red;});
    $(this).text('ab');
    });
    //done
      

  2.   

    本帖最后由 showbo 于 2014-02-14 10:16:46 编辑
      

  3.   

    您是在html中写的吧?
    我如果在js中运用了ext,将样式设置在css文件中,那js中如何使用css呢?
    附上我的一小段js代码:configs = { text: '矢量图', width: 50, id: 'slButton' };
        vectorButton = Ext.create('Ext.Button', configs);
        vectorButton.on("click", vectorButton_click_handler);    function vectorButton_click_handler(item, e, options) {
    。。
    }在vectorButton_click_handler如何添加上样式,从而每次点击时就使用这个样式?
      

  4.   

    一样的。导入css文件就行了你的css或者js放到独立的文件中或者直接放到html中都不会影响结果
      

  5.   

    1、js文件中导入css文件怎么写?
    2、函数中有如何调用它呢?我是这样写的:function include_css(path) {
        var fileref = document.createElement("link")
        fileref.rel = "stylesheet";
        fileref.type = "text/css";
        fileref.href = path;
    }
    function InitializePage()
    {
        configs = { text: '矢量图', width: 50, id: 'slButton' };
        vectorButton = Ext.create('Ext.Button', configs);
        vectorButton.on("click", vectorButton_click_handler);
        function vectorButton_click_handler(item, e, options) {
            include_css("../Index/css/myminu.css");
            Ext.getCmp('slButton').setIconCls('buttondesinger'); //在../Index/css/myminu.css文件中
            
    }
    ../Index/css/myminu.css文件
    .buttondesinger
    {
    width:50;
    background-color:#000000;
    text-align:left;
    }

    您看看这样对吗?
      

  6.   

    function include_css(path) {
        var fileref = document.createElement("link")
        fileref.rel = "stylesheet";
        fileref.type = "text/css";
        fileref.href = path;
    document.getElementsByTagName('head')[0].appendChild(fileref);/////
    }
    include_css("../Index/css/myminu.css");
    function InitializePage()
    {
        configs = { text: '矢量图', width: 50, id: 'slButton' };
        vectorButton = Ext.create('Ext.Button', configs);
        vectorButton.on("click", vectorButton_click_handler);
        function vectorButton_click_handler(item, e, options) {
            
            Ext.getCmp('slButton').setIconCls('buttondesinger'); //在../Index/css/myminu.css文件中
            
    }
    不要在事件中导入,直接导入要不因为css要加载,你的代码第一次可能看不到效果什么的