开发者

JQuery - What method can I use to get this code to run without clicking

Ok this example code contains a button. Forget about the button, it does not exist, cannot be referenced and cannot be edited.

The buttons dont exist in this example - they merely represent another process. However the fields still need to be updated from values. Sorry I couldn't explain it better.

Answer: http://jsfiddle.net/piez开发者_运维技巧ack/X8D4M/56/


If you want the event to fire whenever the text inside the box changes, then I think you're best off using jquery's keyup event instead of blur:

$('#FormCustomObject6Name').keyup(
    function()
    {
        var x = $('#FormCustomObject6Id').val();

        $("a[href*='http://www.msn.com']").attr('href',('http://www.google.com/search?q='+ x));
        $('a#link').text('Link has been updated');   
    }
);

The only problem with this is that it won't catch instances where users enter data without using their keyboard (paste via right click, etc.).


You could use a mouseover event, say over the button or the link.

I changed this

$('.butter').mouseover(function(){

to have a mouseover the button.

Example: http://jsfiddle.net/X8D4M/39/


You can trigger events on objects yourself manually by using trigger(event).

So this might work for you:

$('button.butter').trigger('click');


Did you try just triggering a click?

$('button.butter').click();


Here's what you're looking for.

$('#FormCustomObject6Name').trigger('blur');


Okay, this is probably not the most efficient solution, but if you use setInterval to check for the changed value you're guaranteed to cover all sources of the change.

setInterval(function(){
    var id = $('#FormCustomObject6Id').val();
    var name = x + $('#FormCustomObject6Name').val();
    if (id.length > 0 && name.length > 0){
        $("a[href*='http://www.msn.com']").attr('href',('http://www.google.com/search?q='+ id));
        $('a#link').text('Link has been updated');
    }
},500);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜