onClick仅在我长按

时间:2017-11-09 09:08:53

标签: javascript jquery jsp onclick

当我点击输入字段时,我正试图触发某些功能。事情是,只有点击半秒钟才有效。例如,如果我单击,我会点击进入Windows中的目录,它不能很好地工作。但如果我持续点击更长时间,它的工作正常。有什么建议吗?

这是我的代码。

HTML:

function closeOrderUnit(){
    $('.massclose').click(function(e){
        $(this).parents('td').children('.massbox, .mass_arrow').remove();
        e.preventDefault();
        e.stopPropagation();
    });
}
function changeUnit(){  
    $('.massbox input').click(function(){
        var label = $(this).parents('.massbox').parents("td").children("div").children('label');
        var input = $(this).parents('.massbox').parents("td").children("input.hiddenInput");
        var str = $(this).val();
        //Turning first letter into uppercase
        str = str.toLowerCase().replace(/\b[a-z]/g, function(letter) {
            if(str.length > 2){
                return letter.toUpperCase();
            }else {
                return letter.toLowerCase();
            }
        });
        if(str == "m2"){
            str = str.replace("2", "\u00B2");
        }
        label.html(str);
        input.val($(this).val());
    });
}
function checkUnit(){
    $('.unitinput').each(function(){
        var temp =  $('.massbox').parents("td").children("div").children('label').html();
        if(temp == "m²"){
            temp = "M2";
        }else if(temp == "Rolle"){
            temp = "ROLLE";
        }
        if ($(this).val() == temp)
        {
            $(this).click();
        }
    });

}
function inputValueChanged(){
    $('.js-ordersize-input').change(function(){
    var tmp = $(this).val();
    $(this).attr("value", tmp);
    });

}
function magicMassBox(){
    inputValueChanged();
    closeOrderUnit();
    checkUnit();
    changeUnit();
}
$(document).ready(function() {
    $('.ordersize').each(function(){
        $(this).focus(function(){
            if ($(this).val() == "0")
            {
                $(this).val("");
            }
            $('.massbox, .mass_arrow').remove();
            $(this).parent().append(
                '<div class="massbox"></div>',
                '<div class="mass_arrow"><img alt="arrow" src="/resources/css/screen/images/arrow_box_einheiten.png"></div>'
            );
            var code = $(this).parents('.odd').children('.firstcol').children('input').val();
            if(code == null || code == "")
            {
                code = $(this).parents('.highlighted').children('.firstcol').children('input').val();
            }
            $('.massbox').load('/c/product/units?code='+code, function(responseText, textStatus, XMLHttpRequest){});
        });
        $(this).blur(function(){
            if ($(this).val() == "")
            {
                $(this).val("0");
            }
        });
    });
    $('.ordersize').on('click', function(){
        magicMassBox();
    });
    $(".js-muster-disable").change(handleMusterCheck);
});
<input class="ordersize js-ordersize-input" name="amount_195.050" id="amount_195.050" tabindex="" value="0" type="text">
    <input name="unit_195.050" value="M2" class="hiddenInput" type="hidden">
	<div class="pt5px fleft w25px"><label id="label_195.050">m²</label></div><br>
		<div style="display: none;">
			<div>
				<p>M2</p>
				<p>m²</p>
				<p>m²</p>
			</div>
		</div>
	<div class="massbox">	
	    <p class="masseinheit">Bestelleinheit:</p>
		<div class="clearfix"></div>
			<input class="unitinput" name="unit" value="M2" checked="checked" type="radio">
			m²
			<input class="unitinput" name="unit" value="ROLLE" type="radio">
			Rl.
	</div>

JSP(我必须检查是否启用了某些内容,否则这也会出现在.js中)

<c:if test="${product.enableUnitSelection}">
<script type="text/javascript">
$(document).ready(function() {
    $('.ordersize').each(function(){
        $(this).focus(function(){
            if ($(this).val() == "0")
            {
                $(this).val("");
            }
            $('.massbox, .mass_arrow').remove();
            $(this).parent().append(
                '<div class="massbox"></div>',
                '<div class="mass_arrow"><img alt="arrow" src="/resources/css/screen/images/arrow_box_einheiten.png"></div>'
            );
            var code = $(this).parents('.odd').children('.firstcol').children('input').val();
            if(code == null || code == "")
            {
                code = $(this).parents('.highlighted').children('.firstcol').children('input').val();
            }
            $('.massbox').load('/c/product/units?code='+code, function(responseText, textStatus, XMLHttpRequest){});
        });
        $(this).blur(function(){
            if ($(this).val() == "")
            {
                $(this).val("0");
            }
        });
    });
});
</script>
</c:if>
<script src="/resources/js/webtable.js"></script>

我的.js代码

function closeOrderUnit(){
    $('.massclose').click(function(e){
        $(this).parents('td').children('.massbox, .mass_arrow').remove();
        e.preventDefault();
        e.stopPropagation();
    });
}
function changeUnit(){  
    $('.massbox input').click(function(){
        var label = $(this).parents('.massbox').parents("td").children("div").children('label');
        var input = $(this).parents('.massbox').parents("td").children("input.hiddenInput");
        var str = $(this).val();
        //Turning first letter into uppercase
        str = str.toLowerCase().replace(/\b[a-z]/g, function(letter) {
            if(str.length > 2){
                return letter.toUpperCase();
            }else {
                return letter.toLowerCase();
            }
        });
        if(str == "m2"){
            str = str.replace("2", "\u00B2");
        }
        label.html(str);
        input.val($(this).val());
    });
}
function checkUnit(){
    $('.unitinput').each(function(){
        var temp =  $('.massbox').parents("td").children("div").children('label').html();
        if(temp == "m²"){
            temp = "M2";
        }else if(temp == "Rolle"){
            temp = "ROLLE";
        }
        if ($(this).val() == temp)
        {
            $(this).click();
        }
    });

}
function inputValueChanged(){
    $('.js-ordersize-input').change(function(){
    var tmp = $(this).val();
    $(this).attr("value", tmp);
    });

}
function magicMassBox(){
    inputValueChanged();
    closeOrderUnit();
    checkUnit();
    changeUnit();
}
$(document).ready(function() {
    $('.ordersize').on('click', function(){
        magicMassBox();
    });
    $(".js-muster-disable").change(handleMusterCheck);
});

0 个答案:

没有答案