新年快到到了,先祝高手新年快乐。我是名学生,下个学期我们要学习javascript,我就提前自学了下。请高手看下面的错误。我不管填什么内容,我点击测试时,弹出的永远是:   alert("很好很强大");                        function show()
   {
   var tp=document.getElementById("tp").value;
   var jx=document.getElementById("jx").value;
 if(tp=="天瓶座"&&jx=="巨蟹座")
 {
 alert("很好很强大");
  
 }
 else 
 {
 alert("一般一般");
 }
 
   }
  
                  
<table border="1">
  <tr>
    <td width="58" height="23">星座测试</td>
    <td width="63" align="right">男生星座:</td>
    <td width="77">
    <select name="select2" >
        <option>------</option>
        <option id="tp" value="天瓶座">天瓶座</option>
        <option >巨蟹座</option>
        <option>金牛座</option>
    </select></td>
      <td width="69" align="right">&nbsp;女生星座:</td>
    <td width="76">
      <select name="select">
         <option>------</option>
         <option id="jx"  value="巨蟹座">巨蟹座</option>
         <option >狮子座</option>
         <option>金牛座</option>
      </select></td>
     <td width="59" align="center"><input type="button" value="测试"name="buttonOne" onClick="show()"></td></tr>
</table>

解决方案 »

  1.   

    <option id="tp" value="天瓶座">天瓶座</option>
    改成这样
    <option id="tp" 天瓶座</option>同理
    <option id="jx" value="巨蟹座">巨蟹座</option><option id="jx" >巨蟹座</option>
      

  2.   

    var tp=document.getElementById("tp").options[document.getElementById("tp").selectedIndex].text;
      

  3.   

    获取select的值应该这样:
    var objSelect = document.getElementById("tp");
    var length2 = objSelect.options.length;
    var obj = "";
    for (var i = 0; i < length2; i++) {
    if (objSelect[i].selected == true) {
    obj = objSelect.options[i].text;
    }
    }
            alert(obj);
      

  4.   


      <SCRIPT LANGUAGE="JavaScript">
      <!--
    function show()
    {
    var sel_male = document.getElementById("male"); //取selece对象
    var sel_female = document.getElementById("female");
    alert("所选项的value:"+sel_male.value + "," + sel_female.value);
    alert("所选项的文字:"+sel_male.options[sel_male.selectedIndex].text + "," + sel_female.options[sel_female.selectedIndex].text);
    //sel_male.options是个数组,包含所有的option; sel_male.selectedIndex是选中的option的index
    if(sel_male.value == "tp" && sel_female.value == "jx")
    alert("很好很强大");
    else  
    alert("一般一般");
    }  //-->
      </SCRIPT>
      <table border="1">
      <tr>
      <td height="23">星座测试</td>
      <td align="right">男生星座:</td>
      <td>
      <select name="select2" id="male">
      <option>------</option>
      <option value="tp">天瓶座</option>
      <option value="jx">巨蟹座</option>
      <option value="jn">金牛座</option>
      </select>
      </td>
      <td align="right">&nbsp;女生星座:</td>
      <td>
      <select name="select" id="female">
      <option>------</option>
      <option value="jx">巨蟹座</option>
      <option value="sz">狮子座</option>
      <option value="jn">金牛座</option>
      </select>
      </td>
      <td align="center">
    <input type="button" value="测试"name="buttonOne" onClick="show()">
      </td>
      </tr>
    </table>