小编Hid*_*dde的帖子

jquery验证 - 使用表单标记

所有这些输入标签都在<form></form>标签内

<input  type="text" placeholder="username"><br />
<input  type="text" placeholder="Name"><br />
<input  type="text" placeholder="Lastname"><br />
<input id="mail" type="text" placeholder="E-mail"><br />
<input id="mail_1" type="text" placeholder="Re enter E-mail"><br />
<input id="password" type="password" placeholder="password"><br />
<input id="password_1"  type="password" placeholder="Re enter password"><br /> 
<input id="submit" type="submit" value="registration">
Run Code Online (Sandbox Code Playgroud)

下面的脚本不起作用.sombody可以帮帮我吗?

$("#submit").click(function(){
  var email = $("#mail").val();
  var email_1 = $("#mail_1").val();
  var password = $("#password").val();
  var password_1 = $("#password_1").val();
  if (email != email_1){
    $("#mail,#mail_1").css({"border":"1px solid red","background-color":"#FF9999"});
    alert("wrong mail");
  }
  else{
    $("#mail,#mail_1").css({"border":"1px solid green","background-color":"#C2FFC2"});
  }
  if (password != password_1){ …
Run Code Online (Sandbox Code Playgroud)

javascript jquery

6
推荐指数
1
解决办法
125
查看次数

速度优化:私有和公共变量 - Java

我问这个问题纯粹是为了问题的速度方面.

从私有或公共(Java)获取对象的值之间的速度差异是什么?

class MyClass {
    public int myInt = 5;
}
class MyOtherClass {
    private int myInt = 5;

    public int getMyInt() {
        return myInt;
    }
}
class MyMainClass {
    public static void main (String [] args) {
        MyClass myObject = new MyClass();
        MyOtherClass myOtherObject = new MyOtherClass();

        // which is faster?
        System.out.println(myObject.myInt);
        System.out.println(myOtherObject.getMyInt ());
    }
}
Run Code Online (Sandbox Code Playgroud)

我知道我可以测试它,但如果有人知道它,它不会伤害:)提前谢谢!

java variables performance

5
推荐指数
2
解决办法
6237
查看次数

通过扩展类迭代Arraylist

我一直想知道Java中的一个函数,我希望它存在.我想迭代一个Arraylist(比如A类),它包含类B和C的对象,它们都扩展了A.这个想法,我只想迭代(例如)ArrayList中B类的对象.

这怎么可能,比如下面代码中的简短示例,而没有长代码?

主要课程:

     import java.util.*;

public class Test {

    public static void main(String[] args) {
        new Test ();
    }

    Test() {
        ArrayList<A> a = new ArrayList<A> ();
        a.add (new B ());
        a.add (new C ());
        a.add (new C ());
        a.add (new B ());
        a.add (new C ());
        for (A aObject : a) { // this works, I want it shorter
            if (aObject instanceof B) {
                B b = (B) aObject;
                System.out.println (b.hi);
            }
        }
        for (B b : a) // …
Run Code Online (Sandbox Code Playgroud)

java iteration class

5
推荐指数
1
解决办法
2105
查看次数

Java,BorderLayout.CENTER,获取JPanel的宽度和高度

我正在使用Swing和AWT(为听众)制作一个小程序.我有一个问题,关于获取我的JPanel(名为Chess的类)的大小.我的布局:

public class Main extends JFrame implements MouseListener, ActionListener{

    Chess chessPanel = new Chess ();
    JButton newGameButton = new JButton ("New Game");
    JButton loadGameButton = new JButton ("Load Game");
    JButton saveGameButton = new JButton ("Save Game");
    JButton exitButton = new JButton ("Exit");

    public static void main (String [] args) {
        new Main();
    }

    Main () {
        super ("Chess");
        Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
        setSize(dim);
        setLocation(0,0);
        setUndecorated(true);

        chessPanel.addMouseListener(this);
        add(chessPanel, BorderLayout.CENTER);

        JPanel buttonPanel = new JPanel();
        buttonPanel.setLayout(new FlowLayout());


        newGameButton.addActionListener(this);
        loadGameButton.addActionListener(this);
        saveGameButton.addActionListener(this);
        exitButton.addActionListener(this);

        buttonPanel.add(newGameButton); …
Run Code Online (Sandbox Code Playgroud)

java size swing jpanel

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

如何避免MySQLSyntaxErrorException

我正在使用Java将一些数据插入到mysql中.但是将撇号(标点符号)写入数据(附近的每周跟踪器表明工作增长)它给了我MySQLSyntaxErrorException.请给我适当的解决方案来处理

我的代码是isa

void insert(String a1,String a2, String a3) {
  String nt = a2;
  String pt = a3;
  String tb = a1; 
  query = "insert into "+tb+"(head,des) values('"+nt+"','"+pt+"')"; 
  try {
    stmt.executeUpdate(query);
    System.out.println("inserted"); //con.close();
  } catch (SQLException ex) {
    // Logger.getLogger(conec.class.getName()).log(Level.SEVERE, null, ex);
    ex.printStackTrace();
  }
}
Run Code Online (Sandbox Code Playgroud)

java mysql exception

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

Javascript,for循环不起作用

var a=0;
setTimeout (function () { animatedDraw(context, 20+32*level[0],20*0, textArray[0]); }, timeArray[0]);
setTimeout (function () { animatedDraw(context, 20+32*level[1],20*1, textArray[1]); }, timeArray[1]);
setTimeout (function () { animatedDraw(context, 20+32*level[2],20*2, textArray[2]); }, timeArray[2]);
setTimeout (function () { animatedDraw(context, 20+32*level[3],20*3, textArray[3]); }, timeArray[3]);
setTimeout (function () { animatedDraw(context, 20+32*level[4],20*4, textArray[4]); }, timeArray[4]);
setTimeout (function () { animatedDraw(context, 20+32*level[5],20*5, textArray[5]); }, timeArray[5]);

for (a=0; a<6; a++)
    setTimeout (function () { animatedDraw(context, 20+32*level[a],20*0, textArray[a]); }, timeArray[a]);
Run Code Online (Sandbox Code Playgroud)

我的代码的第一部分是有效的部分.第二部分没有出现.我正在绘制画布(HTML 5),但当我弹出六个警告框时,警告框显示.我做的事情非常愚蠢吗?

提前致谢

javascript arrays for-loop

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

速度:四个整数或一个具有许多操作的整数

我有一个关于Java的速度问题.我正在制作国际象棋程序,我想检查是否最好使用一个int变量来存储四个int变量,其中值的范围是1到4位.

问题是我经常需要提取并放入变量的新部分,因此这将花费相当多的按位操作.

码:

int fromX = 4, fromY = 5, toX = 6, toY = 7;
int move = 0
move |= toY;
move = move << 4;
move |= toX;
move = move << 4;
move |= fromY;
move = move << 4;
move |= fromX;

doWork(move);
Run Code Online (Sandbox Code Playgroud)

要么

int fromX = 4, fromY = 5, toX = 6, toY = 7;
doWork(fromX, fromY, toX, toY);
Run Code Online (Sandbox Code Playgroud)

doWork() 将使用坐标做很多不同的事情,大多从'int'中提取它们,或者只使用变量.

我应该使用哪个?

java variables int performance bit-manipulation

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

memd在2d字符数组上

使用2D数组的int,一切都很好:

 int **p = new int*[8];
 for (int i = 0; i < 8; i++)
    p[i] = new int[8];
 memset(p, 0, 64 * sizeof(int))
Run Code Online (Sandbox Code Playgroud)

但是使用二维数组的字符,我得到一个运行时错误

 char **p = new char*[8];
 for (int i = 0; i < 8; i++)
     p[i] = new char[8];
 memset(p, 0, 64 * sizeof(char));
Run Code Online (Sandbox Code Playgroud)

我的代码出了什么问题?

c++ arrays memset

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

如何在$ {document).ready()上加载脚本

如何使用此代码加载JavaScript

<script type="text/javascript" src="http://uads.ir/l.php?s=125125&w=5307cd5c027373e1773c9869"></script>
Run Code Online (Sandbox Code Playgroud)

页面加载后

$(document).ready(function() 
 {

 }); 
Run Code Online (Sandbox Code Playgroud)

还有另一种方法吗?

javascript jquery

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