값 가져오기
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>
$(function(){
var txt1 = $("#txt1").val();
var hdn1 = $("#hdn1").val();
var slct1 = $("#slct1").val();
alert(txt1);
alert(hdn1);
alert(slct1);
})
</script>
</head>
<body>
<input type="text" id="txt1" value="text1" /><br />
<input type="hidden" id="hdn1" value="hidden1" /><br />
<select id="slct1">
<option value="select1">선택1</option>
<option value="select2" selected="selected">선택2</option>
<option value="select3">선택3</option>
</select>
</body>
</html>
값 변경하기
<script>
$(function(){
$("#txt1").val("값 변경하기")
})
</script>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>
$(function(){
$("#txt1").val("txt2로 값 변경하기")
})
</script>
</head>
<body>
<input type="text" id="txt1" value="text1" /><br />
<input type="hidden" id="hdn1" value="hidden1" /><br />
<select id="slct1">
<option value="select1">선택1</option>
<option value="select2" selected="selected">선택2</option>
<option value="select3">선택3</option>
</select>
<script>
alert($("#txt1").val());
</script>
</body>
</html>