开发者

How to click links with the same name in Javascript

I am trying to figure out how to click all three of these (not at once, separately) using either Javascript or jQuery. I'm using a Python module that executes Javascript code and trying to make a complicated macro, more or less.

Any help is appreciated!

<div class="buttons">
<input type="submit" class="form-submit" value="Save" id="edit-submit" name="op">
<input type="submit" class="form-submit" value="Preview" id="edit-preview" name="op">
<input type="submit" class="form-submit" value="Save and create anothe开发者_如何学Cr" id="edit-submit-again" name="op">
</div>


Jquery's trigger will come in handy for you

$('#edit-submit,#edit-preview,#edit-submit-again').trigger('click');


In javascript you can try this:

var elms=document.getElementsByName("op");
var lunghezza = elms.length;
for (i=0;i<lunghezza ;i++){
     elms[i].click();
};

if you want you can use jquery each();

$('input[name=op]').each(function(){
     $(this).click();
});

If you just want type = submit then do this:

var elms=document.getElementsByName("op");
var lunghezza = elms.length;
    for (i=0;i<lunghezza ;i++){
    if (elms[i].type="submit" ){
       elms[i].click()
    }
    };


If you want to give the submit button a kick:

$("element selection goes here").submit();


This will trigger click on all inputs

$("[name='op']").each(function(){
    $(this).click();
});

If you want to select once at a time, just use their id preceded by a #. Example:

$("#edit-submit").click();


As simple as:

$('#edit-submit').click();

This will trigger the click event, but of course, a user click on the submit button itself will do that as well...

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜