根据选择框值获取标签

时间:2012-10-05 11:36:07

标签: php javascript jquery

我有一个值为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中做到这一点。

帮帮我 乌代

2 个答案:

答案 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选项。

http://jsfiddle.net/4EjGt/6/

<强> 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>