Get the value of the option tag element in the HTML page

When operating form elements, you will inevitably encounter the selection of option elements. The following sample code can get the value of your option element selection. If you want to pass it to the backend, you can pass it through ajax or other methods. can.
Sample code

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>获取option元素</title>
</head>

<body>
  <div class="item-content">
	<div class="item-inner">
	  <div class="item-title label">编程语言</div>
	  <div class="item-input">
		<select id="program-language">
			<option data-id="Java">Java</option>
			<option data-id="Python">Python</option>
			<option data-id="Android">Android</option>
			<option data-id="C#">C#</option>
			<option data-id="Ruby">Ruby</option>
			<option data-id="JavaScript">JavaScript</option>
		</select>
	</div>
  </div>
  
	<div class="content-block">
      <div class="row">
        <div class="col-50">
			<a href="#" class="button button-big button-fill button-success" id="submit">提交</a>
		</div>
      </div>
    </div>
  
<script type='text/javascript' src='C:/Users/Hyxiao/Desktop/option/jquery-3.2.1.js' charset='utf-8'></script>
<script type='text/javascript'>
	$('#submit').click(function() {
     
     
		var  language = '';
		language = 
			$('#program-language').find('option').not(function() {
     
     
				return !this.selected;
			}).data('id')
		console.log(language);
	});
</script>
  
</body>
</html>

The renderings are as follows:
Insert picture description here

Guess you like

Origin blog.csdn.net/hyx1249273846/article/details/113780891
Recommended