我有以下的HTML代码访问HTML元素通过JavaScript
<input type="text" readonly name="Name" class="GadgetName" placeholder="Please Enter the Gadget Name" value="Potatoe Masher" />
<input type="text" readonly name="Description" class="GadgetDescription" placeholder="Please Enter the Gadget Description" value="You'll Never Stop Mashing !" />
<form action="SubmitComment" method="POST">
<div class="Comment">
<textarea rows="4" cols="200" name="Comment" class="GadgetComment" id="Comment2" placeholder="Write Comments Here"></textarea>
<input type="button" value="Submit Comment" class="CommentButton" onclick="AddComment()" />
</div><br />
</form>
我需要访问的只读文本框Name
文本,并在Comment
textarea的文本。
请注意,这些行位于for循环中,因此有多个组件具有相同的类名称。
我设法使用此代码
$(document).ready(function(){
$(document).on("click", ".CommentButton", function(){
text = $("textarea", $(this).parent()).val();
});
});
我现在需要的是访问在Name
文本框中的文本来获得在Comment
textarea的价值。
'$( 'GadgetName')VAL()' – Leeish