2010-06-18 62 views
2

我有一個像jQuery的發現和可變

var theUrl = 'http://www.google.com/?q=%s'; 

一個變量,然後我有一個像

<input type="text" id="searchBox" value="" /> 

一個輸入框,並像

<input type="button" id="searchButton" value="Search" /> 

當一個按鈕替換文本按鈕被點擊,我應該得到一個提醒,其中的變種theUrl應替換爲用戶在文本框中輸入的文本

如何做到這一點?我認爲find()函數只會替換html元素!

請幫

回答

7

你需要調用replace功能,像這樣:

$('#searchButton').click(function() { 
    alert(theUrl.replace('%s', $('#searchBox').val()); 
});