0

The is(:focus) was the aproach. The final code is listed below:

setInterval(function(){
    if($j("SELECT[name='cf20_field_7']").is(":focus")) return false; 
    var information = '';
    var i = 1;
    $j("#cf20_field_1").html();
    //add new information to hidden field
    $j("#cforms20form .info_for_email").each(function(){
        var name = $j(this).find("INPUT[name='cf20_field_5']").val();
        var inn = $j(this).find("INPUT[name='cf20_field_6']").val();
        var view = $j(this).find("SELECT[name='cf20_field_7']").val();
        //render
        information += i + ")";
        information += "Наименование организации: " + name + ".<br/>\n";
        information += "Реквизиты организации: " + inn + ".<br/>\n";
        information += "Стоимость заказа: выписка " + view + ".<br/>\n";
        i++;
    })
    $j("#cf20_field_1").html(information);

    hovered = true;
}
    ,100
);

Is there some possibility to fire function when there is no hover in SELECT field.

And also there may be aproach that to check is there is no hover on SELECT field.

It cause problemms. When you are trying to select another option cursor is begging while setInterval is working.

The best approach that i find is listed below:

//every 100 mil secconds update info
setInterval(function(){

    $j("SELECT[name='cf20_field_7']").trigger('change');
    if ( $j("SELECT[name='cf20_field_7']").on("change")) return false;
    var information = '';
    var i = 1;
    $j("#cf20_field_1").html();
    //add new information to hidden field
    $j("#cforms20form .info_for_email").each(function(){
        var name = $j(this).find("INPUT[name='cf20_field_5']").val();
        var inn = $j(this).find("INPUT[name='cf20_field_6']").val();
        var view = $j(this).find("SELECT[name='cf20_field_7']").attr("value");
        //render
        information += i + ")";
        information += "Наименование организации: " + name + ".<br/>\n";
        information += "Реквизиты организации: " + inn + ".<br/>\n";
        information += "Стоимость заказа: выписка " + view + ".<br/>\n";
        i++;
    })
    $j("#cf20_field_1").html(information);
}
    ,100
);

More information: I can discribe situation more. So i had a form. onsubmit event didn`t work because there is another event is attachet. So i deside to update value of first field of form every 100 milisecs. The value is containing all dynamictly created "selects and inputs". But when i try to change value of the select by mouse. The function is fired and function check value of select and cause mouse begging. So i need somehow to check if that select is hovered to prevent firing of the function.

4

2 回答 2

2

此处无效:

if ( SELECT[name='cf20_field_7'].on("change"))

我猜你需要这个:

if ( $("SELECT[name='cf20_field_7']").on("change"))

但是,以上内容仍然无效。您需要一些处理程序,例如:

$("SELECT[name='cf20_field_7']").on("change", function(){
    return false;
});
于 2013-01-08T10:21:48.697 回答
0
if ($j("SELECT[name='cf20_field_7']").on("change")) return false

不清楚这里应该检查什么。我假设你想运行一些附加到 onchange 的函数,即使是 select。在这种情况下,您应该使用.trigger而不是.on. 但是在这两种情况下,返回值都将是 jquery 对象(用于链接目的),所以基本上你的语句对于triggerandon如果你想测试 select 的某个值,你应该做类似下面的事情:

if(someTestFunct($j("SELECT[name='cf20_field_7']"))) return false;
function someTestFunct(jObj) {
    //some other code?
    return jObj.val() == "some value to test";
}

可能会使用一些更好的方法,但如果没有更多细节,就很难提出建议。

于 2013-01-08T11:07:57.233 回答