我有一个值为1到5的选择框,如果我从选择框中选择值2,我应该得到2个标签或3我应该得到3个标签..
这里是选择框码..
<select id="Week" name="Week">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>
我怎么能在php,javascript或jquery中做到这一点。
帮帮我 乌代
答案 0 :(得分:0)
请试试这个:
<script>
function getTabs()
{
var getSelectedValue = $("#week").val();
if(getSelectedValue == 1)
{
//your specified code for value 1
}
else if(getSelectedValue == 2)
{
//your specified code for value 2
}
//and so on.. upto 5 getSelectedValue values
}
</script>
<select id="Week" onchange="getTabs();" name="Week">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>
答案 1 :(得分:0)
这是一个jQuery选项。
<强> JS 强>
//Global var to track our selected tabs
var m_selectedTabs = $('#tab1');
m_selectedTabs.siblings('span').hide();
$('#Week').change(function(){
SelectTabRangeById($(this).find(':selected').val())
});
function SelectTabRangeById(id){
//Deselect the previous tab
m_selectedTabs.hide();
//Find the new Tab
m_selectedTabs = $('#' + id).prevAll().andSelf();
//Select it
m_selectedTabs.show();
}
<强> HTML 强>
<span id='tab1'>Week 1</span><span id='tab2'>Week 2</span><span id='tab3'>Week 3</span><span id='tab4'>Week 4</span><span id='tab5'>Week 5</span>
<br/>
<select id="Week" name="Week">
<option value="tab1">1</option>
<option value="tab2">2</option>
<option value="tab3">3</option>
<option value="tab4">4</option>
<option value="tab5">5</option>
</select>