我在這個項目中有點失落。我爲一家提供翻譯服務的公司工作。那麼,我正在製作一個簡單的計算器,根據整個項目中的字數計算翻譯成本。它還根據輸入的字數改變比率。我完成了那部分。我寫這個,它的工作原理:需要改變一個按鈕的onClick值到另一個值使用select
function wordcountprice(){
var price, final,
a=document.getElementById('words'),
wc= parseFloat(a.value) || 0;
if(wc< 10000) price= .29;
else price= wc<20000? .26: .24;
final= (wc*price).toFixed(2);
document.getElementById('estPrice').innerHTML = 'Your estimated price is: $' + final;}
在這一點上,我們有6種類型的翻譯工作。其中五個將使用該功能,最後一個將使用具有固定價格的基本功能。我想我會用下拉選擇框來改變功能。
我打電話上述功能在我的HTML這樣的:
<input type="text" id="words"> <input type="button" id="button" value="Calculate" onClick="wordcountprice();"> <br /><b id='estPrice'>Estimated Price</b>
我已經試過幾件事情和他們都沒有工作。我認爲最好的方法是jQuery的change()或select()函數。我試圖做一個新的功能與jQuery像這樣的:
$(function() {
$('#type').change(function() {
var type = $(this).val();
$('#button').val(type);
}); });
這只是改變了按鈕的值,而不是onclick事件。我不知道如何或者是否可以像這樣改變onClick事件。我甚至不知道這是否是我想要做的最有效的方法。我打電話時,我與這個HTML嘗試它是功能:
<select id='type'><option value='1'>A</option>
<option value='2'>B</option>
<option value='3'>C</option>
<option value='4'>D</option></select>
我與jQuery的一個小白並沒有被編程了一段時間,所以我有點生疏。
感謝您的幫助提前。
感謝您的快速回復。我不知道jQuery的屬性函數。我已經嘗試了與我已有的一切並且它完美地工作。謝謝! – Blurn 2011-03-10 00:57:05