0

我在表单中使用 Select 并具有显示“其他”文本输入框的“其他”选项。但是,我只想将实际值保存在表的同一列中,因此我需要确保将“其他”文本输入的“值”传递给 MySQL 表,而不是选定的内容,这显然是“其他” "

<div>
  <select class="element select small" id="prop_title" name="prop_title">
    <option value="Mr" >Mr</option>
    <option value="Mrs" >Mrs</option>
    <option value="Sir" >Sir</option>
    <option value="Lord" >Lord</option>
    <option value="Other">Other</option>
  </select>
  <div id="prop_title_other" style="display: none; margin-top:15px;">
    <label class="description" for="prop_title">Proprietor Title (Other)</label>
    <input type="text" id="prop_title" class="element text small" value=""/>
  </div>
</div> 
$('#prop_title').change(function() 
{
  $('#prop_title_other').css('display', ($(this).val() == 'Other') ? 'block' : 'none');
});
4

2 回答 2

0

$(this)成为文本框的对象。那就是你有这个问题。更改$(this)为局部变量

$('#prop_title').change(function() 
{
  var item=$(this);
   $('#prop_title_other').css('display', (item.val() == 'Other') ? 'block' : 'none');
});

工作样本:http: //jsfiddle.net/GbGbU/

于 2012-05-16T00:09:15.627 回答
0
$('#prop_title').change(function() 
{
  var display;

  if ($(this).val() == 'Other') {
       display = "none";      
  }  else { display = "block"};

  $('#prop_title_other').css('display', display);

});
于 2012-05-16T00:10:15.840 回答