Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/409.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何使用JQuery对blur()调用此函数?_Javascript_Jquery - Fatal编程技术网

Javascript 如何使用JQuery对blur()调用此函数?

Javascript 如何使用JQuery对blur()调用此函数?,javascript,jquery,Javascript,Jquery,我有此功能,请参见以下内容: function checkStartPrice (){ if ($('#StartingPrice')[0].value.length == 0){ alert("The 'Starting Price' cannot be left empty!"); return false; } else { var BuyItNowPrice = parseFloat($('#BuyItNowPrice')

我有此功能,请参见以下内容:

function checkStartPrice (){
    if ($('#StartingPrice')[0].value.length == 0){
        alert("The 'Starting Price' cannot be left empty!");
        return false;
     } else {
        var BuyItNowPrice = parseFloat($('#BuyItNowPrice').val());
        var StartingPrice = parseFloat($('#StartingPrice').val());
        var Reserve = parseFloat($('#Reserve').val());
        if((BuyItNowPrice <= StartingPrice) && (StartingPrice > 0)){
            alert("The 'Buy It Now' price must be higher...");
            return false;
        }
        if((Reserve <= StartingPrice) && (StartingPrice > 0)){
            alert("Your 'Reserve Price' must be higher...");
            return false;
        }
        return true;
    }
}

这是正确的称呼方式。
它可能失败的唯一原因是#StartingPrice元素在.blur()调用时不存在

如果页面中有,请使用以下命令:

$(document).ready(function() {
    $('#StartingPrice').blur(checkStartPrice)
})
如果是通过AJAX动态添加的,请使用以下方法:

$(document).ready(function() {
    $('#StartingPrice').live('blur',checkStartPrice)
})

请注意,第二个解决方案至少需要jQuery 1.4.1

才能工作,即使是
$('#StartingPrice')。如果在
文档中正确调用blur(checkStartPrice)
回调,也可以。必须加载DOM才能工作。看看什么类型的启动价格?它必须是支持模糊的类型event@Felix-Kling错误在我的JS文件中的其他地方…这导致脚本无法工作。谢谢
$(document).ready(function() {
    $('#StartingPrice').live('blur',checkStartPrice)
})