简体   繁体   English

如何使用jQuery更改页面加载时“提交”按钮的显示值

[英]How to change display value of the Submit button on page load using jquery

I am new to JQuery and need suggestions on following requirement. 我是JQuery的新手,并且需要有关以下要求的建议。

I have a form with a submit button as below. 我有一个带有提交按钮的表单,如下所示。 Page accepts locale as an input parameter. 页面接受locale作为输入参数。 Depending on the value of locale , on page load I am populating the labels of the input fields in respective language using jQuery.i18n.properties.js plug-in, but I could not update the display value of the button. 根据locale的值,在页面加载时,我正在使用jQuery.i18n.properties.js插件以相应语言jQuery.i18n.properties.js输入字段的标签,但无法更新按钮的显示值。

Please suggest solution or if there is another way to achieve this. 请提出解决方案,或者是否有其他方法可以实现此目的。

HTML code: HTML代码:

<input type="submit" data-inline="true" id="submit" value="Submit"/>

Have tried below jQuery options to update the button label: 尝试过使用以下jQuery选项来更新按钮标签:

  1. $("#submit").val($.i18n.prop('submit'));
  2. $("#submit").html($.i18n.prop('submit'));
  3. $("#submit").prop('value',($.i18n.prop('submit')));
  4. $("#submit").text($.i18n.prop('submit'));

None of them worked. 他们都没有工作。 But I see the value gets updated as below in Developer tools window, for this button. 但是我看到此按钮的值在开发人员工具窗口中的更新如下。

<div class="ui-btn ui-input-btn ui-corner-all ui-shadow"> Submit <input type="submit" id="submit" value="New Text"> </div>

Try $("#submit")[0].value = $.i18n.prop('submit'); 试试$("#submit")[0].value = $.i18n.prop('submit'); . Does that work for you? 那对你有用吗?

(Even though it's a JS workaround, not a JQuery solution) (即使这是JS解决方法,也不是JQuery解决方案)

If your button is an input tag, use the jQuery val : 如果您的按钮是input标签,请使用jQuery val

 function changeBtnText() { $("#submit").val("My new button text"); } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <input type="submit" id="submit" value="My button"> <button type="button" onclick="changeBtnText()">Change button text</button> 

If your button is a button tag, use the jQuery text (or html ): 如果您的按钮是button标签,请使用jQuery text (或html ):

 function changeBtnText() { $("#submit").text("My new button text"); } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <button type="submit" id="submit">My button</button> <button type="button" onclick="changeBtnText()">Change button text</button> 

Note: I recommend giving your button an ID different from "submit" to avoid confusion. 注意:建议您为按钮提供一个不同于“提交”的ID,以免造成混淆。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 单击后如何使用JavaScript或jQuery更改Submit按钮的值? - How to change the value of submit button after click using JavaScript or jQuery? 防止页面加载到jQuery表单上,而无显示按钮 - Prevent Page Load on Jquery Form Submit with None Display Button jQuery更改按钮类,其中页面加载时value = myValue - JQuery change the button class where value = myValue on page load 如何在不使用jQuery在AngularJS中提交页面加载表单? - How to submit a form on page load without using jquery in AngularJS? 如何使用jQuery和MySQL在同一页面上提交和显示? - How to Submit and Display on the same page using jQuery and MySQL? 单击提交按钮时,如何使用jQuery重新加载cakephp中的页面 - How to reload page in cakephp using jQuery when clicking the submit button 使用jQuery在页面加载时获取单选按钮的默认值 - Getting default value of radio button upon page load using jQuery jQuery将发布值发送到另一个页面并加载到当前页面中。 显示更多,显示更多按钮 - jquery send post value to another page and load in current page. Show more, display more button jQuery更改单选按钮和页面加载上的CSS - jquery change css on radio button and page load 使用javascript我如何将其更改为在页面加载时显示? - using javascript how would I change this to display on page load?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM