获取与输入相关的动态创建选择的值

时间:2015-10-26 10:18:25

标签: javascript jquery

我坚持使用正确的元素,我希望你能帮助我。

所以: 我有 PHP 脚本生成的字段:

<fieldset>

  <div class="row">
    <select>
      <option value="A">A</option>
      <option value="B">B</option>
    </select>
    <input type="text" />
  </div>
  <div class="row">
    <select>
      <option value="A">A</option>
      <option value="B">B</option>
    </select>
    <input type="text" />
  </div>


</fieldset>

我需要在焦点上的每个文本字段上初始化一个自动完成插件,基于行中选择内部选择的内容,文本框在哪里。

由于我没有访问权限的项目模板,我无法编辑行或ID类(如编号行),所以即使这是一个简化的解决方案,它就像我正在使用的一样

所以,再一次,我需要实现的目标:

    $(input).focus(function(){
Ask_what_is_in_select_at_the_same_row()
Store_value_of_Selected_Option_to_Variable()

});

1 个答案:

答案 0 :(得分:1)

你可以这样使用它:

$('div.row :text').focus(function(){
    // get the value of the select which is the sibling of focussed text input.
    var optVal = $(this).siblings('select').find('option:selected').val();
    // now you can use it.
});

DEMO