gpt4 book ai didi

php - 一个js文件在另一个php文件中的Javascript : calling document. ready()函数

转载 作者:行者123 更新时间:2023-11-28 14:03:51 25 4
gpt4 key购买 nike

我有包含以下代码的 progress.js 文件

            $('#text_area_input').keyup(function()
{
var text_area_box =$(this).val();//Get the values in the textarea
var max_numb_of_words = 160;//Set the Maximum Number of characters
var main = text_area_box.length*100;//Multiply the lenght on words x 100
var value= (main / max_numb_of_words);//Divide it by the Max numb of words previously declared
var count= max_numb_of_words - text_area_box.length;//Get Count of remaining characters
if(text_area_box.length <= max_numb_of_words)
{
$('#progressbar').css('background-color','#5fbbde');//Set the background of the progressbar to blue
$('#count').html(count);//Output the count variable previously calculated into the div with id= count
$('#progressbar').animate(//Increase the width of the css property 'width'
{
'width': value+'%'
}, 1);//Increase the
}
else
{
$('#progressbar').css('background-color','yellow');
//If More words is typed into the textarea than the specified limit ,
//Change the progress bar from blue to yellow
var remove_excess_characters =text_area_box.substr(0,max_numb_of_words);
$('#text_area_input').val(remove_excess_characters);
//Remove the excess words using substring
}
return false;
});
});

我必须在我的 php 文件中调用该函数。我怎么能做对呢?我在我的元素中包含了所有必要的 css

最佳答案

嗯,有一个很好的解决方案。而不是像这样在 document.ready 工作中使用它

<input type = 'button' onkeyup = 'my_function();' id = 'text_area_input'>

你的脚本应该包含这个

 <script type = 'text/javascript'>
function my_function(){
// you code here
}
<script>

如果您正在调用此文件中的其他 php 文件,则此函数也可用于新的 php 文件。另一种解决方案是将代码复制到另一个 php 文件中

关于php - 一个js文件在另一个php文件中的Javascript : calling document. ready()函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10101717/

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