2011-08-30 118 views
0

希望我能從你們那裏得到幫助。我在下面得到了一個簡單的腳本,但不知道爲什麼這不起作用。JQuery:如果其他選擇下拉

想要限制文本區域的文本長度取決於選擇的下拉值。請指教。 HTML:

<select class="productoptionname_card-type" id="Option111453" name="Option111453">         
<option value="">Please select...</option> 
<option value="1127125">Free Message Card</option> 
<option value="1127126">Greeting Cart</option> 
</select> 
<textarea class="productoptionname_message" style="width: auto" tabindex="5"></textarea> 
<span id="charsLeft"></span> 

JQuery的:

<script src="http://code.jquery.com/jquery-1.4.4.min.js" type="text/javascript"></script> 
<script src="http://jquery-limit.googlecode.com/files/jquery.limit-1.2.source.js" type="text/javascript"></script> 
    <script language="javascript"> 
function ResetText() { 
    if ($('#Option111453 option:selected').text() == "Free Message Card") { 
     $('textarea.productoptionname_message').limit('5','#charsLeft'); 
    } 
    else if ($('#Option111453 option:selected').text() == "Greeting Cart") { 
     $('textarea.productoptionname_message').limit('10','#charsLeft'); 
    } 
} 
$().ready(function() { 
    $('textarea.productoptionname_message').keyup(function() { ResetText(); }); 
    $('#Option111592').change(function() { ResetText(); }); 
}); 
</script> 

謝謝了!

+2

首先'Function'將不會工作。或者是一個錯字? JavaScript區分大小寫。 –

+0

你正在使用'limit'功能的插件嗎? – sje397

+0

你的html和javascript不匹配。 – xdazz

回答

0

擴展名(JQuery.limit)無法正常工作。

我只是爲你寫一個自定義的jquery限制擴展。

你可以在這裏進行測試:http://jsfiddle.net/tcWHr/

相關問題