如何删除没有价值的选项选择?
How can i remove option selection without value?
我在尝试删除选项或隐藏搜查代码中的第一个选项值时遇到问题。
你能帮我解决这个问题吗?
我有这个HTML代码
<select id="q_c_0_a_0_name">
<option value></option>
<option value="lastanem1">First Lastname</option>
<option value="lastname2">Second Lastname</option>
...
<option value="xxxxxxxxx">Other value</option>
</select>
我正在尝试删除选项或隐藏第一个选项,因为 Ransack gem 正在生成以下 HTML 代码:
<select id="q_c_0_a_0_name">
<option value="name"> Filter by Name</option>
<option value="lastanem1">Filter by First Lastname</option>
<option value="lastname2">Filter by Second Lastname</option>
...
<option value="xxxxxxxxx">Filter by Other value</option>
</select>
我试过这个 JQuery 代码:
$(function(){
$("#q_c_0_a_0_name option[value=]").style.display = "none";
});
也尝试了这个 JQuery 代码:
$(function(){
$("#q_c_0_a_0_name option[value=""]").style.display = "none";
});
试试这个代码
$("#q_c_0_a_0_name option[value='name']").remove();
您可以删除下面的第一个选项,无论它包含什么值。
$("#q_c_0_a_0_name").find("option").eq(0).remove();
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<select id="q_c_0_a_0_name">
<option value="name"> Filter by Name</option>
<option value="lastanem1">Filter by First Lastname</option>
<option value="lastname2">Filter by Second Lastname</option>
...
<option value="xxxxxxxxx">Filter by Other value</option>
</select>
使用:first
/ :first-child
$("#q_c_0_a_0_name option:first").remove();
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<select id="q_c_0_a_0_name">
<option value></option>
<option value="lastanem1">First Lastname</option>
<option value="lastname2">Second Lastname</option>
<option value="xxxxxxxxx">Other value</option>
</select>
我在尝试删除选项或隐藏搜查代码中的第一个选项值时遇到问题。
你能帮我解决这个问题吗?
我有这个HTML代码
<select id="q_c_0_a_0_name">
<option value></option>
<option value="lastanem1">First Lastname</option>
<option value="lastname2">Second Lastname</option>
...
<option value="xxxxxxxxx">Other value</option>
</select>
我正在尝试删除选项或隐藏第一个选项,因为 Ransack gem 正在生成以下 HTML 代码:
<select id="q_c_0_a_0_name">
<option value="name"> Filter by Name</option>
<option value="lastanem1">Filter by First Lastname</option>
<option value="lastname2">Filter by Second Lastname</option>
...
<option value="xxxxxxxxx">Filter by Other value</option>
</select>
我试过这个 JQuery 代码:
$(function(){
$("#q_c_0_a_0_name option[value=]").style.display = "none";
});
也尝试了这个 JQuery 代码:
$(function(){
$("#q_c_0_a_0_name option[value=""]").style.display = "none";
});
试试这个代码
$("#q_c_0_a_0_name option[value='name']").remove();
您可以删除下面的第一个选项,无论它包含什么值。
$("#q_c_0_a_0_name").find("option").eq(0).remove();
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<select id="q_c_0_a_0_name">
<option value="name"> Filter by Name</option>
<option value="lastanem1">Filter by First Lastname</option>
<option value="lastname2">Filter by Second Lastname</option>
...
<option value="xxxxxxxxx">Filter by Other value</option>
</select>
使用:first
/ :first-child
$("#q_c_0_a_0_name option:first").remove();
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<select id="q_c_0_a_0_name">
<option value></option>
<option value="lastanem1">First Lastname</option>
<option value="lastname2">Second Lastname</option>
<option value="xxxxxxxxx">Other value</option>
</select>