簡體   English   中英

在具有特定屬性的表單內設置輸入字段的值?

[英]Set the value of an input field inside a form with a specific attribute?

我有以下 html。 我需要一個 jquery 選擇器來設置表單內隱藏屬性 (SelectedEntityID) 的值,並使用以下屬性 (data-ajax="true"):

    <form  action="/myServer/List/ToolbarFunction" method="post">
    <input name="SelectedEntityID" id="SelectedEntityID" type="hidden" value="">
    </form>

    <form  action="/myServer/List/AjaxToolbarFunction" method="post" data-ajax="true" data-ajax-success="SuccessMessage" data-ajax-method="POST" data-ajax-failure="FailMessage">
    <input name="SelectedEntityID" id="SelectedEntityID" type="hidden" value="">
    </form>

注意:我需要輸入元素 (SelectedEntityID) 位於兩個表單內並具有相同的 ID。

我嘗試了以下方法:

$("form[data-ajax='true'] #SelectedEntityID").val('123')

但該值未設置並且瀏覽器控制台中沒有錯誤。

id在頁面中應該是唯一的。 您可以使用name來選擇元素

$("form[data-ajax='true'] input[name='SelectedEntityID']").val('123')

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM