1

我在下面使用code,它显示???仅代替result. 你能帮我纠正error下面表格中的错误吗?消息显示空白结果,如 ?? 格式。有什么帮助吗?--

<table width="100%" border="0" cellspacing="2" cellpadding="2">
  <tr>
    <td width="12%">&nbsp;</td>
    <td width="2%">&nbsp;</td>
    <td width="2%">&nbsp;</td>
    <td width="2%">&nbsp;</td>
    <td width="16%">&nbsp;</td>
    <td width="66%">&nbsp;</td>
  </tr>
  <tr>
    <td><img src="images/australia1.jpg" width="132" height="70"></td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td><select name="select">
      <option>Select Course Type</option>
      <option>Under Graduate</option>
      <option>Post Graduate</option>
    </select>
    </td>
    <td><div id="message"></div>​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​&lt;/td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>

</table>
<script type="text/javascript" language="javascript">
var messages = {
    Under Graduate: 'UG text is here',
    Post Graduate: 'PG text is here'
}
$('select').change(function() {
    $('#message').text(messages[$(this).val()]);
});​
</script>
4

4 回答 4

0

您的消息对象中有语法错误。您需要在其中包含空格的键周围使用引号:

var messages = {
    'Under Graduate': 'UG text is here',
    'Post Graduate': 'PG text is here'
}
于 2012-11-28T12:37:59.930 回答
0

我认为您只是缺少value属性并使用单字标识符

<option vale="under_graduate">Under Graduate</option>

var messages = {
    under_graduate: 'UG text is here',
    val1: 'PG text is here'
}
</script>
于 2012-11-28T12:38:14.440 回答
0
<script type="text/javascript" language="javascript">
var messages = {
    under: 'UG text is here',
    post: 'PG text is here'
}
$('select').change(function() {
    if($(this).val() != '')
        $('#message').text(messages[$(this).val()]);
});​
</script>

<select name="select">
  <option value="">Select Course Type</option>
  <option value="under">Under Graduate</option>
  <option value="post">Post Graduate</option>
</select>
于 2012-11-28T12:40:11.950 回答
0

试试这个

  <script type="text/javascript" language="javascript">


  $('#select').change(function() {

    var selectVal = $('#select :selected').val();
     $(#message).text(selectVal);

});
   </script>

并更换

    <select name="select">

经过

   <select id="select">
于 2012-11-28T12:51:19.903 回答