简体   繁体   English

如何使用 jQuery 更改 Wordpress 帖子中的多个同名输入元素?

[英]How to change multiple same name input element in Wordpress post with jQuery?

I can change Wordpress input element with different name.我可以使用不同的名称更改 Wordpress 输入元素。 As for example the following input element:例如以下输入元素:

<input class="wpProQuiz_button" type="button" value="Start Quiz" name="startQuiz">

can be changed with the following jQuery code:可以使用以下 jQuery 代码更改:

jQuery("input[name='startQuiz']").attr("value", "Start Mock Test");

Question:题:

How can I do the same for the following with same name input element in Wordpress?如何在 Wordpress 中对以下具有相同名称的输入元素执行相同的操作?

<input type="button" name="next" value="Next" class="wpProQuiz_button wpProQuiz_QuestionButton" style="float: right;">

<input type="button" name="next" value="Quiz-summary" class="wpProQuiz_button wpProQuiz_QuestionButton" style="float: right;">

I have use the following for the above two input element like :我对上述两个输入元素使用了以下内容,例如:

jQuery("input[name='next']").attr("value", "Next");
jQuery("input[name='next']").attr("value", "Test-summary");

But it is not working.但它不起作用。 How can I do this?我怎样才能做到这一点?

use jQuery selectors:使用 jQuery 选择器:

jQuery("input[name='next']:first-child").val("zzzz"); jQuery("input[name='next']:first-child").val("zzzz"); jQuery("input[name='next']:nth-child(2)").val("qqqqq"); jQuery("input[name='next']:nth-child(2)").val("qqqqq");

and take in mind "float:right" :)并记住“浮动:正确”:)

more examples here: https://api.jquery.com/category/selectors/child-filter-selectors/更多示例: https : //api.jquery.com/category/selectors/child-filter-selectors/

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

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