JQuery:如果选择下拉列表中的其他内容

时间:2011-08-30 01:47:10

标签: javascript jquery character limit

希望我可以得到你们的帮助..我在下面有一个简单的脚本,但不确定为什么这不起作用。

想要限制textarea的文本长度取决于选择下拉值。请指教。 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>

非常感谢!

1 个答案:

答案 0 :(得分:0)

扩展名(JQuery.limit)无法正常运行。

我只是为你编写一个自定义jquery限制扩展。

您可以在此处测试:http://jsfiddle.net/tcWHr/