简体   繁体   English

第一次单击选择未选择值

[英]First click on select doesn't selecting the value

Hello i got problem with my select box in HTML. 您好,我的HTML选择框出现问题。 First click on this box sometimes doesn't selecting the value but only "focusing" it? 第一次单击此框有时不选择值而是仅“聚焦”它? (i don't know that this is a good word for it) I made screen to help You explain what i mean: (我不知道这是一个好词)我做了屏幕帮助您解释我的意思:

Link to image 链接到图片

What can i do to avoid this? 我该怎么做才能避免这种情况? When user will click i have to show the right place on the map 当用户单击时,我必须在地图上显示正确的位置

Some parts of my code: 我的代码的某些部分:

echo '<select id="selector'.$i.'" style=" height: 100%; width: 228px; margin: 2px;" onchange="JumpToPoint(this.value);">';
while($street = mysql_fetch_array($streets, MYSQL_ASSOC))
{
   echo '<option value="'.$street['x'].','.$street['y'].'">'.$street['name'].'</option>';        
}
echo '</select></div>';

It is any possibility to simulate this focus ? 有没有可能模拟此焦点? Because only first click is focusing value - the socond, third etc always selecting the right value 因为只有第一次点击才是聚焦值-第二,第三等总是选择正确的值

I found that the problem is with this function: 我发现问题在于此功能:

    jQuery.fn.filterByText = function(textbox) {
    return this.each(function() {
        var select = this;
        var options = [];
        $(select).find('option').each(function() {
            options.push({value: $(this).val(), text: $(this).text()});
        });
        $(select).data('options', options);

        $(textbox).bind('change keyup', function() {
            var options = $(select).empty().data('options');
            var search = $.trim($(this).val());
            var regex = new RegExp(search,"gi");

            $.each(options, function(i) {
                var option = options[i];
                if(option.text.match(regex) !== null) {
                    $(select).append(
                        $('<option>').text(option.text).val(option.value)
                    );
                }
            });
        });
    });
};

But i don't know where 但是我不知道在哪里

Thanks in advance for help. 在此先感谢您的帮助。

I don't see why you don't just use the 'change' event for your jQuery event instead of the 'click' event so going with the code you put up and assuming you are using jQuery try this : 我不明白为什么您不只对jQuery事件使用'change'事件而不是'click'事件,所以继续您编写的代码并假设您使用的是jQuery,请尝试以下操作:

<script type="text/javascript">
$(document).ready(function() {
   $('#selector<?php echo $i ?>').change(function() {
      /** change map code goes here **/
   });
});
</script>

add this line before while loop.I think this helps u. 在while循环之前添加此行。我认为这对您有所帮助。

echo '---select----'; 回声'--- select ----';

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM