我試圖做一個簡單的窗體和按鈕的工作。我已經連接到JS小提琴這裏View JS Fiddle here將表單和按鈕鏈接到javascript命令
<form>
<input type="text" class="form-control" id="search" placeholder="enter sport">
<button type="submit" id="WFFsearch">Search</button>
</form>
$('#WFFsearch').on('click', function() {
var searchInput = $('#search').text();
var url = "http://espn.go.com/" + searchInput + "/statistics";
window.open(url);
});
我希望能夠進入「NBA」不帶引號,然後點擊搜索按鈕,然後有其生成以下鏈接http://espn.go.com/nba/statistics一個新窗口。所有網址的第一部分和最後部分將是相同的,它只是中間的變化(nba,nfl,mlb)。任何幫助將不勝感激,謝謝!