![zahl zahl]()
本文介绍了使用AJAX功能更改提交按钮即可立即响应输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我想改变在这种形式的输入中给出答案(为数字提供俄语)的可能性,从提交按钮到动态AJAX函数,以立即得到答案。 / p> 谢谢!!! 在@ user1978142的帮助下,它的效果很好。 但是现在我搜索一个解决方案来添加一个播放按钮,它用Google TTS(文字转语音)来表示我找到了Google TTS的解决方案,但它只适用于Google Chrome。 $ ru = new NumberFormatter(ru,NumberFormatter :: SPELLOUT); ?> < form method =getaction =index.php> Zahl:< input name =zahltype =textsize =15maxlength =15> < input type =submitvalue =Anzeigen> < / form> if(is_numeric($ _ REQUEST ['zahl']))echo $ ru-> format($ _ REQUEST ['zahl']); ?> 解决方案由于jQuery被标记, $ c> NumberFormatter 已经安装,一个简单的 $。ajax 就是你所需要的。记录编码(我认为 ru 是针对俄语)。考虑这个例子: 您的 index.php < form method =POSTaction =index.php> < label for =zahl> Zahl:< / label> <峰; br /> < input id =zahlname =zahltype =numbersize =15maxlength =15>< br />< br /> < div id =resultsstyle =width:400px;>< / div> <! - 结果出现在这里 - > < / form> < script src =// ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js\"></script> < script type =text / javascript> $(document).ready(function(){ $('#zahl')。on('keyup',function(){ // ajax request server $ .ajax({url:'number_process.php',type:'POST',dataType:'text',data:{value:$(this).val()}, success: function(response){ $('#results')。text(response); //追加到结果div } }); }); }); < / script> number_process.php (样品名称) 创建将处理ajax请求的php文件。这将处理它并返回您的价值。 <?php if(isset($ _POST ['value'])){ $ ru = new NumberFormatter(ru,NumberFormatter :: SPELLOUT); //正常处理 $ value = $ ru-> format($ _ POST ['value']); echo mb_convert_encoding($ value,'UTF-8','auto'); //俄语字符 exit; } ?> I want to change the possibility to get the answer of the value in the input in this form (to provide the russian word for a number) from the submit-Button to a dynamic AJAX-function to get the answer instantly.Thank you !!!With the help of @user1978142 it works perfectly.But now I search for a solution to add a Play-Button, which spellout the word with Google TTS (Text-To-Speech)I find a solution for Google TTS, but it only works on Google Chrome.<? $ru = new NumberFormatter("ru", NumberFormatter::SPELLOUT); ?><form method="get" action="index.php"> Zahl: <input name="zahl" type="text" size="15" maxlength="15"> <input type="submit" value="Anzeigen"></form> <? if (is_numeric($_REQUEST['zahl'])) echo $ru->format($_REQUEST['zahl']);?> 解决方案 Since jQuery is tagged, and given that NumberFormatter is already installed, a simple $.ajax is all you need. Take note of the encoding also (I think ru is meant for russian). Consider this example:Your index.php<form method="POST" action="index.php"> <label for="zahl">Zahl:</label> <br/> <input id="zahl" name="zahl" type="number" size="15" maxlength="15"><br/><br/> <div id="results" style="width: 400px;"></div> <!-- results appear here --></form><script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script><script type="text/javascript">$(document).ready(function(){ $('#zahl').on('keyup', function(){ // ajax request server $.ajax({ url: 'number_process.php', type: 'POST', dataType: 'text', data: {value: $(this).val()}, success: function(response) { $('#results').text(response); // append to result div } }); });});</script>number_process.php (Sample Name)Create the php file that will handle the ajax request. This will process it and return your value.<?phpif(isset($_POST['value'])) { $ru = new NumberFormatter("ru", NumberFormatter::SPELLOUT); // normal processing $value = $ru->format($_POST['value']); echo mb_convert_encoding($value, 'UTF-8', 'auto'); // russian characters exit;}?> 这篇关于使用AJAX功能更改提交按钮即可立即响应输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 09-17 02:01