Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/81.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript json发送时字符串的第一个字母大写_Javascript_Jquery_Jquery Ui_Getjson_Jquery Ui Autocomplete - Fatal编程技术网

Javascript json发送时字符串的第一个字母大写

Javascript json发送时字符串的第一个字母大写,javascript,jquery,jquery-ui,getjson,jquery-ui-autocomplete,Javascript,Jquery,Jquery Ui,Getjson,Jquery Ui Autocomplete,我有一个文本框,可以根据cityname从JSON文件中搜索城市,当我在文本框中键入时,我必须用大写字母R写第一个字母,否则我的代码就不能正常工作 我怎样才能在我的代码中引入首字母大写的术语 我使用css将第一个字母改为大写,但它不适用于我,而是用小写字母发送 这是我的密码: <input autocomplete="off" class="autocomplete-hint select" data-auto-complete-minlength="1" type="text" onF

我有一个文本框,可以根据cityname从JSON文件中搜索城市,当我在文本框中键入时,我必须用大写字母R写第一个字母,否则我的代码就不能正常工作

我怎样才能在我的代码中引入首字母大写的术语

我使用css将第一个字母改为大写,但它不适用于我,而是用小写字母发送

这是我的密码:

<input autocomplete="off"  class="autocomplete-hint select" data-auto-complete-minlength="1" type="text" onFocus="searchCountry(this)">

<script type="text/javascript">

    function searchCountry(a) {
        $(function() {
            var cache = {};
            $(a).autocomplete({
                appendTo: ".countrys",
                change: function (event, ui) {
                    if (ui.item == null || ui.item == undefined) {
                        $(a).val("");
                        $(a).empty();
                        $(a).next("#loading").hide();
                    } else {
                        var position = $(".countrys").position(),
                        left = position.left, top = position.top;
                        $(".countrys > ul").css({
                            left: left + 20 + "px",
                            top: top + 4 + "px"
                        });
                    }
                },
                minLength: 1,
                select: function (event, ui) {
                    // Set autocomplete element to display the label
                    this.value = ui.item.label;
                    $(this).closest("tr").find(".countryid").val(ui.item.hotelid);
                    $(this).closest("tr").find(".countryid").next(".countryid").val(ui.item.hotelid);

                    // Store value in hidden field
                    $('#hidden_field').val(ui.item.id);
                    $('#hidden_field1').empty().text(ui.item.label);

                    // Prevent default behaviour
                    return false;
                },
                source: function( request, response ) {
                    $(a).next("#loading").show();
                    var term = request.term;
                    if (term in cache) {
                        response(cache[term]);
                        return;
                    }

                    $.getJSON( "jsonloadi.bc", request, function( data, status, xhr ) {
                        $(a).next("#loading").hide();
                        cache[ term ] = data;
                        response( data );
                    });
                }
            });
        });
    }
</script>

您可以使用以下函数将任何字符串大写

这里,第一个字符使用string.charAt0.toUpperCase更改为大写,其余字符更改为小写。您可以使用此功能修改请求,如下所示

source: function( request, response ) {
  request.term = capitalizeFirstLetter(request.term)
  ...

我还没有对此进行测试,但它应该可以正常工作。

即使是从samei复制的函数名,我也无法在代码中找到request.term=,当我将其添加到:var term=request.term;我的代码根本不起作用是的,您必须将其作为新行添加。此外,如果console中有任何错误,请将其也附加。@MuhammadOmerAslam,OP的要求是向服务器发送大写术语,而不仅仅是大写字符串。这就是这个问题不重复的原因。请先阅读要求。
source: function( request, response ) {
  request.term = capitalizeFirstLetter(request.term)
  ...