父输入的值

时间:2015-07-13 00:55:12

标签: javascript jquery

从select name change [] val(),我想从它的父输入id冠军[]用JQuery获得输入但是我得到

  

'未定义'错误

<div id="p_scents">
        <p>    
            <label for="p_scnts">
                <input type="text" id="champion[]" size="20" list="champions" value=""  placeholder="Enter Champion's name">
                <datalist id="champions"></datalist>
                <a href="#" id="addGeneral">Add General Change</a><a></a>
                <a href="#" id="addSpell"> Add Spell</a><a></a>
                   <a>
                        <p>
                            <select name="change[]" id="change[]" onchange="val()"></select>
                            <label for="var" readonly="true">
                                 <input type="text" id="championSpell[]">
                                 <br>
                                 <textarea type="text" id="p_scnt" size="20" name="p_scnt_2" value="" placeholder="Enter Description"></textarea>
                                 <select></select>
                            </label>
                            <a href="#" id="addGeneral">Add Change</a>
                            <a href="#" id="remVar">Remove Spell</a></p></a>
            </label>
        </p>
</div>

var championName = $(&#34;#change&#34;)。nearest(&#39; input&#39;)。val();

1 个答案:

答案 0 :(得分:0)

<强> HTML

<select name="change[]" id="change[]" onchange="val(this)"></select>

<强>的Javascript

function val(elm) {
  var championName = $(elm).closest("label").find("input").val();

  alert('champion name is ' + championName);
}