HTML
- 1 ответ
- 0 вопросов
0
Вклад в тег
<form ..>
<input class="form-control city1 only-ru" type="text" name="city1" id="city1" placeholder="откуда" value="" autocomplete="off" >
<input class="form-control city2 only-ru" type="text" name="city2" id="city2" placeholder="куда" value="" autocomplete="off" >
...
</form>
//поменять name при фокусе
$('.only-ru').on("focus", function(){
var realFields = [];
var realFieldsMapper = {};
$(this).each(function(i) {
realFields[i] = $(this).attr('name');
if(realFieldsMapper[realFields[i]]) {
$(this).attr('name', realFieldsMapper[realFields[i]]);
} else {
var randomName = Math.random().toString(36).replace(/[^a-z]+/g, '');
$(this).attr('name', randomName);
realFieldsMapper[realFields[i]] = randomName;
}
});
});
//поменять name обратно
$(document).mouseup(function (e){
var div1 = $("#city1"), div2 = $("#city2");
if (!div1.is(e.target)) $("input#city1").attr('name', 'city1');
if (!div2.is(e.target)) $("input#city2").attr('name', 'city2');
});