How to select specific form element in jQuery?

前端 未结 5 1530
清歌不尽
清歌不尽 2020-11-30 20:47

I have two form like this:

<
5条回答
  •  离开以前
    2020-11-30 21:05

    It isn't valid to have the same ID twice, that's why #name only finds the first one.

    You can try:

    $("#form2 input").val('Hello World!');
    

    Or,

    $("#form2 input[name=name]").val('Hello World!');
    

    If you're stuck with an invalid page and want to select all #names, you can use the attribute selector on the id:

    $("input[id=name]").val('Hello World!');
    

提交回复
热议问题