gpt4 book ai didi

javascript - 第二个函数没有被调用

转载 作者:行者123 更新时间:2023-11-28 08:56:13 26 4
gpt4 key购买 nike

这只是我一直在努力解决的问题。我创建了两个函数,如下所示:

function limit_char_normal(textid, limit, infodiv){
var text = $('#'+textid).val();
var textlength = text.length;

if (textlength > limit) {
alert("Number of characters exceeded!");
$('#'+textid).val(text.substr(0,limit));
return false;
}else{
$('#' + infodiv).html(''+ (limit - textlength) +'');
return true;
}
};

function limit_char_unicode(textid, limit, infodiv){
var text = $('#'+textid).val();
var textlength = text.length;

if (textlength > limit) {
alert("Number of characters exceeded!");
$('#'+textid).val(text.substr(0,limit));
return false;
}else{
$('#' + infodiv).html(''+ (limit - textlength) +'');
return true;
}
}

$(document).ready(function() {
$("#normal").click(function() {
$('#infodiv').show();
$('#infodiv2').hide();
$('#normal_message').val('');
$('#normal_message').bind('keyup keydown click',function(){
limit_char_normal('normal_message', 153, 'infodiv');
});
});
$("#unicode").click(function() {
$('#infodiv2').show();
$('#infodiv').hide();
$('#normal_message').val('');
$('#normal_message').bind('keyup keydown click',function(){
limit_char_normal('normal_message', 63, 'infodiv2');
});
});
});

<input type="radio" name="normal_message" value="normal" id="normal">Normal
<input type="radio" name="normal_message" value="unicode" id="unicode">Unicode

<textarea rows="4" cols="50" name="normal_message" class="normal_message" id="normal_message" placeholder="Hello Message">
</textarea>

<p id="infodiv" style="display:none;">153</p>
<p id="infodiv2" style="display:none;">63</p>

当我单击普通按钮时,功能工作正常。单击普通按钮后,我单击 unicode 按钮,它工作正常,字符扣除也没有问题。

点击 unicode 按钮并点击恢复正常后,它只调用函数 limit_char_unicode() 而不会调用 limit_char_normal() 函数。

我已经包含了 jsfiddle 供您引用。

http://jsfiddle.net/caocao89/FMNSt/

如果你能帮忙的话那就太好了。

最佳答案

您定义了一个名为 limit_char_unicode 的函数,并且不会从任何地方调用它。

$("#unicode").click(function() {
$('#infodiv2').show();
$('#infodiv').hide();
$('#normal_message').val('');
$('#normal_message').bind('keyup keydown click',function(){
limit_char_normal('normal_message', 63, 'infodiv2');
});
});

将上述函数中的limit_char_normal更改为limit_char_unicode并尝试。

关于javascript - 第二个函数没有被调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18456353/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com