Reprinted from: http://blog.csdn.net/superit401/article/details/72629519
- <input name="a" id="1" value="南海">
- <input name="a" id="2" value="特朗普">
- <input name="a" id="3" value="月光宝盒">
- <input name="a" id="4" value="大话西游">
- $(function(){
- // get the number of elements
- alert($('input:[name="a"]').length); //4
- //Get the new way of writing the value of the first element
- alert($('input:[name="a"]:first').val()); //南海
- //Get the new way of getting the last element value
- alert($( 'input:[name="a"]:last' ).val()); // Westward Journey
- //Get the second element value writing
- alert($( 'input:[name="a"]:eq(1)' ).val()); //Trump
- })