2017-04-19 69 views
0

我試圖通過簡單地使用JQuery設置.val()來單擊按鈕時重置值。最奇特的地方happening-我的代碼只是工作狀態下拉列表而不是其他的投入,已與痛飲插直列設置像這樣它們的值:更改具有插值的輸入值字段

<input type="text" class="moving-input form-control" id="first-name-search" value="{{search.firstName}}"> 

當點擊這個按鈕:

<button type="reset" class="results-form-link" id="perform-new-search">Perform a New Search</button> 

應該運行此代碼:

$('#perform-new-search').click(function() { 
    $('#first-name-search').val('hello'); 
    $('#last-name-search').val(''); 
    $('#results-states option:selected').val('Select State'); 
}) 

什麼奇怪的是,如果我嘗試運行$(「#直呼其名的搜索」)VAL(「你好」);在控制檯直接在瀏覽器中工作,但點擊按鈕時不起作用。

回答

0
$('#perform-new-search').click(function() { 

    $('#first-name-search').val('hello'); 
    $('#last-name-search').val(''); 
    $('#results-states option:selected').val('Select State'); 
}) 

好像它的工作,

檢查https://jsfiddle.net/aLLrku6r/

+0

右它應該工作,但一些事情上本身變得無法正常工作的HTML的輸入值的插值。 (值=「{{search.firstName}}」) – Linx

+0

這應該是有益的 - [鏈接] http://stackoverflow.com/questions/1408289/how-can-i-do-string-interpolation-in-javascript – Neetigya