データ属性を使用して選択しています。最初の選択のデータ属性に基づいてフィルタリングしたいと思います。これが私のコードです、何を教えてください?私のコードの乱雑さを失礼します、私はjavascript /Jquerynoobです
htmlブロック/////////
<select id="selectOne">
<option data-team='{"team":"Engineering"}'>Engineering </option>
<option data-team='{"team": "Software"}'>Software Development</option>
<option data-team='{"team": "HumanResources"}'>Human Resources</option>
<option data-team='{"team": "MarkettingAndSales"}'>Marketting and Sales</option>
<option data-team='{"team": "Administrative"}'>Administrative</option>
<option data-team='{"team": "Others"}' class="others">Others</option>
</select>
<select id="selectTwo">
<option class="two" data-Speciality='{"team": "Software", "Speciality": "WebDevelopment"}'>Web Development </option>
<option class="two" data-Speciality='{"team": "Engineering", "Speciality": "WebApplication"}'>Application Development </option>
<option class="two" data-Speciality='{"team": "Software", "Speciality": "WebDevelopment"}'>UI/UX Design</option>
<option class="two" data-Speciality='{"team": "Others", "Speciality": "ScientificResearch"}'>Scientific / Research</option>
<option class="two" data-Speciality='{"team": "Engineering", "Speciality": "ScientificResearch"}'>Computer Hardware / Networking</option>
<option class="two" data-Speciality='{"team": "Others", "Speciality": "Others"}'>Others</option>
</select>
$(function(){
// function to use ajax calls to filter the table data depending on the select forms value
$("#selectOne").change(function() {
$("#selectTwo").hide();
var selected = $(this).find('option:selected');
$('#selectTwo option [data-team===selected]').show();
console.log( $(selected).data('team') );
//the filtering mechanism based on the class
});
///どうやら私は2番目の値を取得していないのはなぜですか?
$(function(){
// function to use ajax calls to filter the table data depending on the select forms value
$("#selectOne").change(function() {
var selected=$(this).find('option:selected').data('team').teamName;
console.log(selected);
var selectTwo= $('#selectTwo').val().data('Speciality').team;
console.log(selectTwo);
})