Javascript 比较文本字段和选择列表值以及警报

Javascript 比较文本字段和选择列表值以及警报,javascript,Javascript,我有一个文本字段,其中的值在屏幕加载时填充,还有一个选择列表 我的问题是,当用户在选择列表中选择一个值,并与文本字段进行比较,如果该值不相等,则触发一条警报消息 请帮忙 JS: function doType() { if (document.getElementById("Text1").value != document.getElementById("Select1").value) alert(document.getElementById("Select1"

我有一个文本字段,其中的值在屏幕加载时填充,还有一个选择列表

我的问题是,当用户在选择列表中选择一个值,并与文本字段进行比较,如果该值不相等,则触发一条警报消息

请帮忙

    JS:
function doType() 
{
    if (document.getElementById("Text1").value != document.getElementById("Select1").value) 
    alert(document.getElementById("Select1").value)
}

HTML:
<tr>
        <td align="right"><b>Select 1:</b></td>
        <td align=left>
           <select name="Select1" onChange="doType();"></select>
        </td>
        <td align="right"><b> Text 1:</b></td>
        <td align="left">
            <input name="Text1" type="text" size="10" maxlength="10">
        </td>
    </tr>
JS:
函数doType()
{
if(document.getElementById(“Text1”).value!=document.getElementById(“Select1”).value)
警报(document.getElementById(“Select1”).value)
}
HTML:
选择1:
案文1:
JS:

function doType()
    {
      if(document.getElementById("Select1").value === document.getElementById("Text1").value){
        alert("Equal");
       }

      else{
       alert(" Not Equal");
      }
    }
HTML:


苹果
橙色
菠萝
香蕉

JS:function doType(){if(document.getElementById(“Text1”).value!=document.getElementById(“Select1”).value)警报(document.getElementById(“Select1”).value)}HTML:Select 1:Text 1:I已尝试但无法工作:(我尝试分别对文本字段值和选择列表值发出警报。文本字段值不出现这是因为您没有将
id
同时提供给Selectbox和textfield。您必须将
id
分配给每个元素,以便在Javascript中访问它们的值。)
<select id="Select1"onChange="doType();">
<option>Apple</option>
<option>Orange</option>
<option>Pineapple</option>
<option>Banana</option>
</select>

<input id="Text1" type="text" value="Apple"/>