2013-02-17 80 views
0

當我的頭撞到一個小時後,這種簡單的事情終於結束了。使用jquery無法獲取文本輸入的值

我只是想收集有關ajax提交的信息。

我可以做的是檢索屬性值,我可以設置文本輸入的值,然後檢索該值,但如果該值由用戶手動設置,我無法檢索該值。出於測試目的,我添加了一些按鈕,這些按鈕表現了我嘗試過的一切。

我也有它設立的jsfiddle和它的作品有細 http://jsfiddle.net/x6p5k/

我懷疑問題出在我使用 http://srobbin.com/jquery-plugins/pageslide/

感謝您的幫助pageslide jQuery插件某處

HTML

<label class="control-label" for="inputName">Name</label> 
    <div class="controls"> 
    <input type="text" id="inputName" name="inputName" value="" placeholder="Name"> 
    </div> 

<label class="control-label" for="inputEmain">Email</label> 
    <div class="controls"> 
    <input type="text" id="inputEmail" name="inputEmail" value="" placeholder="Email Address"> 

... 

<button type="button" class="btn btn-primary pull-right" id="value">value</button> 
<button type="button" class="btn btn-primary pull-right" id="type">type</button>  
<button type="button" class="btn btn-primary pull-right" id="set_value">set value</button> 

的jQuery

$("#value").click(function() 
    { 
    var Variablename = $("#inputName").val(); 
    window.alert(Variablename); 
    }); 

$("#type").click(function() 
    { 
    var Variablename = $("#inputName").attr("type"); 
    window.alert(Variablename); 
    }); 

$("#set_value").click(function() 
    { 
    $("input#inputName").val("hello world"); 
    }); 

網站我試圖得到這個工作的是,當你點擊頂部菜單上接觸的模式http://whispersofawillow.org

回答

0

我認爲你正在使用2周的div相同ID的事實:

$("input#inputName").length 

與上述線路檢查您的控制檯。

每當您將表單添加到您的頁面時,新的輸入將被添加到您的頁面,因爲我已經調查過。

+0

$('#inputName')。length'返回1。 – jagzviruz 2013-02-17 19:18:05

+0

nope,它返回2在我的情況 – 2013-02-17 19:18:43

+0

這是相當奇怪的.. – jagzviruz 2013-02-17 19:20:01