简体   繁体   中英

Change value on type=submit

This is a very easy topic, but I don't seem to make any solution on Google work. I am working on a hack-around for a form. I can't add id's or classes. All i have is type=submit . What is the easiest solution to change the text on the button?

$( document ).ready(function() {
    var $input = document.find("input[type=submit]");
    $input.val('OLOLOLOL');
});

OR

$( document ).ready(function() {
        $(':submit').val('OLOLOLOL');
    });

HTML

<input type="submit" value="Submit">

They don't change anything. Is it syntax or something worse? Plain javascript can work too

i would try this:

$( document ).ready(function() {
    var $input = $(document).find("input[type=submit]");
    $input.val('OLOLOLOL');
});

I would use input[type=submit] selector for the search as in this fiddle :

$("input[type=submit]").val("New value");

As far as I know, jQuery uses the same selectors as CSS does (and many others )!

How about this:

$( document ).ready(function() {
    var $input = $(document).find("input[type=submit]");
    $input.val('OLOLOLOL');
});

First one works only for input type button but second one works for both input type button as well as button type submit.

So, choice is yours if you want to bind the function anyway if the type is button choose second option.

But I just saw your edited question and would do like this:

$('input[type="submit"]').val("Your Value");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM