【问题标题】:How to change multiple same name input element in Wordpress post with jQuery?如何使用 jQuery 更改 Wordpress 帖子中的多个同名输入元素?
【发布时间】:2021-12-05 23:26:07
【问题描述】:

我可以用不同的名称更改 Wordpress 输入元素。比如下面的输入元素:

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

可以使用以下 jQuery 代码进行更改:

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

问题:

如何在 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;">

我对上述两个输入元素使用了以下内容,例如:

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

但它不起作用。我该怎么做?

【问题讨论】:

    标签: javascript jquery wordpress post


    【解决方案1】:

    使用 jQuery 选择器:

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

    记住“float:right”:)

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

    【讨论】:

    • @VladimirMiroshnichenko "jQuery("input[name='next']:first-child").val("zzzz"); " 和 " jQuery("input[name='next'] :nth-child(2)").val("qqqqq");"不工作。
    猜你喜欢
    • 1970-01-01
    • 2014-11-18
    • 2013-12-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多