Javascript 如何使用 JQuery 设置提交按钮的文本?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2294881/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-22 23:38:38  来源:igfitidea点击:

How to set the text of a submit button using JQuery?

javascriptjquery

提问by TIMEX

For some reason $("#thebutton").val("New text")doesn't work.

由于某种原因$("#thebutton").val("New text")不起作用。

回答by Darin Dimitrov

Well, this works for me (tested on Chrome 4, FireFox 3.6, IE8):

嗯,这对我有用(在 Chrome 4、FireFox 3.6、IE8 上测试):

<html>
<head>
    <title>Test</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js"></script>
    <script type="text/javascript">
    $(function() {
        $("#thebutton").val("New text");
    });
    </script>
</head>
<body>
    <input id="thebutton" type="submit" value="OK" />
</body>
</html>

回答by Tepu

If you are using html button i.e. <button id='thebutton ' > Button Val </button>then use $("#thebutton").text("NEW Text");

如果您使用的是 html 按钮,<button id='thebutton ' > Button Val </button>则使用$("#thebutton").text("NEW Text");