更改jquery事件无法正常运行

时间:2013-01-16 06:11:37

标签: jquery

$(document).ready( function() {
 $('#date').bind("change",function(){
  var x=$("#date").val();
  alert(x);
 });
});

对应的HTML代码:

 <form id="form1">
  <tr>
    <td class="tr_tab"><a class="qtn_data">I am:</td><td class="tr_tab"> </a> 
      <input type="radio value="male" name="gender" /><a class="qtn_data">Male</a>&nbsp
      <input type="radio" value="female" name="gender"/>
      <a class="qtn_data">Female</a>

    </td>
  </tr>
  <tr>
    <td colspan="2">
      <hr/ id="hr3">
    </td>
  </tr>
  <tr>
     <td class="tr_tab"><a class="qtn_data">Date of birth:</td><td class="tr_tab"> </a> 
      <input type="text" name="date" placeholder="Date" MaxLength="2" id="date" />&nbsp
      <input type="text" placeholder="Month" MaxLength="2" id="month" />&nbsp
      <input type="text" placeholder="Year" id="year" MaxLength="4" />&nbsp</td>
  </tr>
  <tr>
    <td></td>
    <td><span style="float:left;"><a class="qtn_data1">ex: 02/05/1992</a></span>

    </td>
  </tr>
  <tr>
    <td colspan="2">
      <hr/ id="hr3">
    </td>
  </tr>
  <tr>
    <td><a class="qtn_data">I am from:</a>

    </td>
    <td>
  <input type="text" id="place" placeholder="Town" />
    </td>
  </tr>
  <tr>
    <td></td>
    <td>
      <input type="text" id="place" placeholder="State" />
    </td>
  </tr>
  <tr>
    <td></td>
    <td>
      <input type="text" id="place" placeholder="Country" />
    </td>
  </tr>
</form>

当我使用Opera更改文本框中的文字后,当我移动到另一个窗口时,Firefoxid="date"会显示警报,但在Chrome中没有效果..

2 个答案:

答案 0 :(得分:1)

有不完整的HTML

更改

  <tr>
     <td class="tr_tab"><a class="qtn_data">Date of birth:</td><td class="tr_tab"> </a> 
      <input type="text" name="date" placeholder="Date" MaxLength="2" id="date" />&nbsp
      <input type="text" placeholder="Month" MaxLength="2" id="month" />&nbsp
      <input type="text" placeholder="Year" id="year" MaxLength="4" />&nbsp</td>
  </tr>

  <tr>
     <td class="tr_tab"><a class="qtn_data">Date of birth: </a> </td>
     <td class="tr_tab">
      <input type="text" name="date" placeholder="Date" MaxLength="2" id="date" />&nbsp
      <input type="text" placeholder="Month" MaxLength="2" id="month" />&nbsp
      <input type="text" placeholder="Year" id="year" MaxLength="4" />&nbsp
     </td>
  </tr>

此处您已关闭</td>,然后关闭</a>

<td class="tr_tab"><a class="qtn_data">Date of birth:</td><td class="tr_tab"> </a> 

其他地方也有HTML个错误,请检查并更正

答案 1 :(得分:0)

试试这个

详细了解如何绑定change事件......

http://api.jquery.com/change/

EX: -

$(document).ready( function()
    $('#date').click(function() {
      $('#date').change();
    });

    $('#date').change(function() {
       var x=$("#date").val();
       alert(x);
    });
});