我在phonegap构建中遇到了一个问题,这是一个运行两次(在手机上用phonegap构建)的函数,不同的是当我在firefox上执行脚本时。Js函数在phonegap上运行2次构建
那是我的代码的一部分:
$(".blackcase").click(function(e)
{
if (elemIsEmpty($(this)) && isSelected("black"))
{
return;
}
if (isSelected("white"))
{
//swap white to black
alert("swap b to w");
if ($(this).html() == valueoffirst.html())
{
$(valueoffirst.html(""));
alert("swap b to w1");
}
else
{
swapValuesFromTo($("#" + selectedCase.id), $(this));
alert("swap b to w 2");
}
clearSelectedCase();
removeSelectionWithRed();
return;
}
if (isSelected("black"))
{
alert("swap b to b");
$("#" + selectedCase.id).removeClass('red');
if ($(this).html() == valueoffirst.html() && $(this).attr('id') != valueoffirst.attr('id'))
{
$(valueoffirst.html(""));
alert("swap b to b1");
}
else
{
swapValuesFromTo($("#" + selectedCase.id), $(this));
alert("swap b to b 2");
}
clearSelectedCase();
removeSelectionWithRed();
return;
}
//alert("black is selected");
selectWithRed($(this));
updateSelectedCase("black", $(this).attr("id"), $(this).html());
valueoffirst = $(this);
});
function removeSelectionWithRed()
{
$('div').removeClass('red');
}
function selectWithRed(element)
{
removeSelectionWithRed();
element.addClass('red');
}
function updateSelectedCase(color, id)
{
selectedCase.color = color;
selectedCase.id = id;
}
function moveValueFromTo(elemFrom, elemTo)
{
elemTo.html(elemFrom.html());
setValueToElem("", elemFrom);
}
function setValueToElem(value, elem)
{
elem.html(value);
}
function swapValuesFromTo(elemFrom, elemTo)
{
var fromValue = elemFrom.html();
var toValue = elemTo.html();
setValueToElem(fromValue, elemTo);
setValueToElem(toValue, elemFrom);
}
function isSelected(color)
{
return selectedCase.color == color;
}
function clearSelectedCase()
{
selectedCase.color = "";
selectedCase.id = "";
}
function elemIsEmpty(elem)
{
return elem.html().length == 0;
}
当我运行我的Firefox代码,如果我上的黑色外壳,然后双击另一个blackcase,它的交换价值,我有两个警报:
交换的b to b
交换b键B2
一切正常,但我的手机和我的phongap版本测试,如果我在blackcase单击然后又blackcase值不换,我有4个警报:
交换的B to B
交换b键B2
交换的B to B
交换b键B2
因此,我认为值交换但重新交换,因此值与起始值相同(如没有任何更改)。
非常感谢您的帮助!
听起来就像是在不停地添加您的点击处理程序。这里是'$(“。blackcase”)。click(function(){})' –
'请调用,谢谢,是的,但我没有承认为什么它在Firefox上没问题,有一个用于phonegap或另一个js规范想这样? – Sanalol