2015-04-17 186 views
0

我想知道爲什麼我不能訪問變量的值(「撥號」)任何幫助將是偉大的。爲什麼我不能訪問變量jQuery的功能

<input type="text" class="dial" value="50" /> 
 
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> 
 
    <script src="https://raw.githubusercontent.com/aterrien/jQuery-Knob/master/dist/jquery.knob.min.js"></script> 
 
<script type="text/javascript"> 
 
    $(function() { 
 
        var dial = $(".dial"); 
 
        
 
        function onDialChange(){ 
 
         console.log(dial.value); // for some probably obvious reason I can't access this value. 
 
        } 
 
        
 
        dial.knob({ 
 
         'release':function(){}, 
 
         'change':onDialChange, 
 
         'draw':function(){}, 
 
        }); 
 
            
 

 
       }); 
 
</script>

+2

是在腳本標記你的代碼? – brso05

+1

'value'是DOM元素的屬性,而不是jquery對象。你必須使用'.val()'方法代替 – hindmost

+0

是的,它在後面更新 – rinserepeat

回答

3

.val()是在jquery的適當的函數返回輸入元素的值。

console.log(dial.val()); 

爲了您Reference

4
function onDialChange(){ 
    console.log(dial.val()); //for value 
    console.log(dial.text()); //for text 
} 
+0

哇這是我的愚蠢謝謝你! – rinserepeat

+0

@ rinserepeat你可以標記它回答:) – ozil

相關問題