小编Cha*_*her的帖子

jQuery - a:not()中的多个选择器?

我似乎无法得到以下工作:

$('input:not([type=radio][type=checkbox])').live('click', function() {
    alert("You haven't clicked a radio or checkbox!");
});
Run Code Online (Sandbox Code Playgroud)

尝试了一些不同的语法,任何人都可以帮我解决这个问题.

干杯
查理

jquery jquery-selectors

46
推荐指数
2
解决办法
3万
查看次数

jQuery - 检查元素是否有数组中的类?

我试图检查一个元素是否有一个数组的类,如果是这样,该类的值是什么.目前我正在使用:

if ($(this).hasClass('purple_grad')) {
            $thisFKeyColour = 'purple_grad';
        } else if ($(this).hasClass('red_grad')) {
            $thisFKeyColour = 'red_grad';
        } else if ($(this).hasClass('green_grad')) {
            $thisFKeyColour = 'green_grad';
        } else if ($(this).hasClass('blue_grad')) {
            $thisFKeyColour = 'blue_grad';
        } else if ($(this).hasClass('yellow_grad')) {
            $thisFKeyColour = 'yellow_grad';
        } else if ($(this).hasClass('light_yellow_grad')) {
            $thisFKeyColour = 'light_yellow_grad';
        } else if ($(this).hasClass('lighter_yellow_grad')) {
            $thisFKeyColour = 'lighter_yellow_grad';
        } else if ($(this).hasClass('grey_grad')) {
            $thisFKeyColour = 'grey_grad';
        } else if ($(this).hasClass('light_grey_grad')) {
            $thisFKeyColour = 'light_grey_grad';
        } else if ($(this).hasClass('black_grad')) {
            $thisFKeyColour = 'black_grad';
        } …
Run Code Online (Sandbox Code Playgroud)

html javascript jquery dom class

9
推荐指数
2
解决办法
1万
查看次数

jQuery - 将元素传递给函数

嗨,我有一个函数,我想通过单击元素或通过元素作为参数调用函数来传递元素.这就是我所拥有的:

function change_btm_cat(item) {
        $('div.prod_matrix').removeClass('block');
        $('div.prod_matrix').addClass('none');
        $('div.prod_matrix#'+item.attr('id')).removeClass('none');
        $('div.prod_matrix#'+item.attr('id')).addClass('block');
        $('div.btm_cat').removeClass('green_grad');
        $('div.btm_cat').addClass('grey_grad');
        item.removeClass('grey_grad');
        item.addClass('green_grad');
        //ps. i know its messy, just testing stuff
    }
Run Code Online (Sandbox Code Playgroud)

我可以轻松地使用它来工作:

$('div.btm_cat').click(function() {
        change_btm_cat($(this));
    });
Run Code Online (Sandbox Code Playgroud)

但当我尝试:

$('another.element').live('click', function() {
   change_btm_cat($('div.btm_cat#7'));
});
Run Code Online (Sandbox Code Playgroud)

它似乎没有通过任何功能.

有关工作示例,请参阅jsFiddle:http: //jsfiddle.net/rb7ZG/1/

jquery element function

7
推荐指数
2
解决办法
3万
查看次数

Javascript - 变量失去其价值并"变得"未定义

我似乎在某种程度上失去了变量即时设置的价值......

我试图做的并不是那么重要,所以我设置了一个(评论很好的)jsFiddle来向你展示我的成果.代码如下.

如果有人可以看到什么进展任何帮助,赞赏:)

请参阅jsFiddle> http://jsfiddle.net/qNWuV/4/ <建议您查看此处

var habs = ["417,77", "410,363", "388,433", "262,435", "262,210", "391,101", "384,183", "61,114", "331,171", "164,433", "361,248", "302,329", "154,307", "410,350", "173,298", "308,429"]; //just an array of co-ords for another part of my app. Only the .length is used below.

//############################
// NOTE: as this problem depends on random numbers you MAY not see it. If "undefined" is ANYWHERE in the Result, the problem is occurring, otherwise re-run the code.
//############################


function link_habs(habs) {
    var test2 …
Run Code Online (Sandbox Code Playgroud)

javascript random variables jquery

7
推荐指数
1
解决办法
1580
查看次数

jQuery - 绑定点击除了类之外的所有元素?

我试图将点击绑定到没有特定类的所有元素.

我尝试了下面的内容,经过一些googleing,它看起来是正确的做法.

$('*:not(.class)').click(function() {
    alert('Clicked...');
});

$(':not(.class)').click(function() {
    alert('Clicked...');
});
Run Code Online (Sandbox Code Playgroud)

现在,我在写这篇文章时刚刚意识到,元素是在其他元素之上分层的,而点击下的所有元素也会引发点击?它是否正确?我认为就像执行以下代码一样,每次点击可获得3到6次"点击".

$('*').click(function() {
    console.log('click');
});
Run Code Online (Sandbox Code Playgroud)

有人有光线吗?

编辑(已经):我刚刚想到了一个解决方法,如下:

$('*').click(function() {
    if ($(this).hasClass('class')) {
        console.log('click');
        return false;
    } else {
        console.log('click');
    }
});
Run Code Online (Sandbox Code Playgroud)

逻辑:这个"class"元素将是顶层元素,因此将触发第一次单击(理论制作),因此它具有我们返回/中断的类;

jquery click

3
推荐指数
1
解决办法
1万
查看次数

Swing组件的定位Java - JPanel,JButton,JFrame

我目前正在研究Java GUI实现,对于我的下一个任务,我们将创建一个程序来模拟房屋的控制.我们已经获得了非常自由的统治来构建它,但是我们喜欢它(只要它在Java中).我已经制定了这个模型:http://i.imgur.com/9RtWL7b.jpg(如下所示),这就是我想要制作的东西.

程序样机: 程序样机

下面是我目前的代码,它产生了这个http://i.imgur.com/XZLiwWx.jpg(下面)

示例代码如下: 程序示例

我的问题是; 如何让三个按钮位于屏幕左侧?我是以错误的方式来做这件事的吗?我觉得我下面的代码非常笨重而且没有组织,我应该采取不同的方法吗?

如果需要更多信息,请与我们联系.

import java.awt.*;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Image;

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JButton;

public class ImageTest {

    public static void main(String[] args) {
        ImagePanel panel            = new ImagePanel("program/assets/main_bg.jpg");

        TopTabButton buttonHome     = new TopTabButton("home");
        TopTabButton buttonSettings = new TopTabButton("settings");
        TopTabButton buttonHelp     = new TopTabButton("help");

        panel.add(buttonHome);
        panel.add(buttonSettings);
        panel.add(buttonHelp);


        panel.setPreferredSize(new Dimension(1000, 760));

        JFrame frame = new JFrame();
        frame.setBackground(new Color(53, 56, 64));
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        frame.getContentPane().add(panel);

        frame.pack();

        frame.setLocationRelativeTo(null);
        frame.setResizable(false); …
Run Code Online (Sandbox Code Playgroud)

java swing jpanel jbutton layout-manager

2
推荐指数
2
解决办法
3万
查看次数

Javascript - for循环挂?

也许我刚刚盯着这个屏幕太长时间,但我似乎无法弄清楚为什么这个for循环挂起?

var not = '3,7';
var nots = not.split(',');
alert(nots.length);
for (var i = 0; i <= nots.length; i++) { 
    nots[i] = parseInt(nots[i], 10);
}
document.write(nots);
Run Code Online (Sandbox Code Playgroud)

谢谢你的帮助.

干杯
查理

javascript for-loop hang

0
推荐指数
1
解决办法
335
查看次数