c'est un problème très étrange ...Un javascript problème ambigu objet
voir ce code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="zh-CN">
<head>
<title>TEST</title>
<script src="http://misc.fandongxi.com/js/jquery.1.4.js" type="text/javascript"></script>
</head>
<body>
<a href="#" id="p1">click this to change p1.x</a>
<a href="#" id="p2">click this to change p2.x</a>
<input id="p1_val" value="">
<input id="p2_val" value="">
<script language="JavaScript">
a = function(id) {
this.inputid = id+'_val';
othis = this;
$('#'+id).click(function(){
othis.x += 1;
$('#'+othis.inputid).val(othis.x);
});
}
p1 = new a('p1');
p1.x=1;
p2 = new a('p2');
p2.x=1;
</script>
</body>
</html>
je veux cliquer sur l'ID « p1 » pour faire P1.x ajouter 1 et cliquez sur le "P2" pour faire p2.x ajouter 1
mais
le problème est de cliquer sur l'un d'eux ... le p2.x ajoutera 1
attendait la réponse ....
très merci :)
je ne suis pas bon en anglais .... peut-être que je ne fais pas clairement le problème;