首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > Ajax >

ajax获取text的值为空咋回事呢?<input id="birds">取出的值是空

2012-04-09 
ajax获取text的值为空怎么回事呢?input idbirds取出的值是空 - Web 开发 / AjaxHTML code!DOCTYPE h

ajax获取text的值为空怎么回事呢?<input id="birds">取出的值是空 - Web 开发 / Ajax

HTML code
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312" /><title></title><script src="./jQuery UI Autocomplete - Remote datasource_files/jquery-1.5.1.js"></script><script src="./jQuery UI Autocomplete - Remote datasource_files/jquery.ui.core.js"></script><script src="./jQuery UI Autocomplete - Remote datasource_files/jquery.ui.widget.js"></script><script src="./jQuery UI Autocomplete - Remote datasource_files/jquery.ui.position.js"></script><script src="./jQuery UI Autocomplete - Remote datasource_files/jquery.ui.autocomplete.js"></script><META HTTP-EQUIV="Pragma" CONTENT="no-cache"><META HTTP-EQUIV="Cache-Control" CONTENT="no-cache"><META HTTP-EQUIV="Expires" CONTENT="0"><link rel="stylesheet" href="demos.css"><link rel="stylesheet" href="jquery.ui.all.css"><style>    .ui-autocomplete-loading { background: white url('images/ui-anim_basic_16x16.gif') right center no-repeat; }</style><!--<script type="text/javascript">    $(function () {    $('input:text:first').focus();    var $inp = $(':input');    $inp.bind('keydown', function (e) {                var key = e.which;        //window.alert(e.ctrlKey);        if (key == 13||(e.ctrlKey&&key == 13)) {            e.preventDefault();            if(this.type=="submit")            {                document.forms[0].submit();            }            var nxtIdx = $inp.index(this) + 1;            $(":input:eq(" + nxtIdx + ")").focus();        }    });});</script>--> <script type="text/javascript">$(function(){    $("#myform input:text").keypress(function(e)    {        if (e.which == 13)//判断所按是否回车键        {            var inputs = $("#myform").find(":text");//获取表单中的所有输入框            var idx = inputs.index(this);//获取当前焦点输入框所处的位置                        if (idx == inputs.length - 1)// 判断是否是最后一个输入框            {               // if (confirm("最后一个输入框已经输入,是否提交?"))   //用户确认                    $("#myform").submit();    //提交表单            }            else            {                inputs[idx + 1].focus();//设置焦点                inputs[idx + 1].select();//选中文字            }            return false;//取消默认的提交行为        }    });});</script><script>    $(function() {        function log( message ) {            $( "<div/>" ).text( message ).prependTo( "#log" );            $( "#log" ).attr( "scrollTop", 0 );        }                var textval = $("#birds").attr("value");//         alert(textval);        $( "#birds" ).autocomplete({            //source: "search.php",            source: 'search.php?ts='+new Date().getTime()+'&k='+encodeURIComponent(textval),            //source: 'search.php?ts='+new Date().getTime()+'&k='+encodeURIComponent(ui.item.value),            minLength: 2,            select: function( event, ui ) {                log( ui.item ?                    "Selected: " + ui.item.value + " aka " + ui.item.id :                    "Nothing selected, input was " + this.value );            }        });        //$( "#birds1" ).autocomplete({        //    source: "search.php",        //    minLength: 2,        //    select: function( event, ui ) {        //        log( ui.item ?        //            "Selected: " + ui.item.value + " aka " + ui.item.id :        //            "Nothing selected, input was " + this.value );        //    }        //});    });</script></head><body><table width="736" height="127" border="1"><form method="post" action="" id="myform"><div class="demo">  <tr>    <td colspan="4">方剂类型:</td>  </tr>  <tr>    <td colspan="2">        <input type="radio" name="radiobutton" value="radiobutton" />茶剂    </td>    <td width="107">        <input type="radio" name="radiobutton" value="radiobutton" />药剂    </td>    <td width="437">        <input type="radio" name="radiobutton" value="radiobutton" />汤剂    </td>  </tr>  <tr>    <td colspan="4">查询药剂:</td>  </tr>  <tr>    <td width="168">        <div class="ui-widget">            <label for="birds">Birds: </label>            <input id="birds">        </div>      </label>    </td>    <td colspan="2">        <input type="text" name="textfield2" size="6" />克    </td>    <td>        <input name="Input" type="button" value="确认" />    </td>  </tr>  </form>  </div>  </table><div class="ui-widget" style="margin-top:2em; font-family:Arial">Result:<div id="log" style="height: 200px; width: 300px; overflow: auto;" class="ui-widget-content"></div></div></body></html> 



[解决办法]
没得测试就是麻烦,你应该在input的onchange或者onkeyup事件当中判断有无值,有值再进行autocomplete

热点排行