gpt4 book ai didi

javascript - 不在
中的隐藏 <input> 包含在 "tab"序列中

转载 作者:行者123 更新时间:2023-11-30 17:24:43 25 4
gpt4 key购买 nike

在 google maps v3 中,我使用的是信息窗口。我使用以下变量作为信息窗口的内容(因为我不知道在这种情况下如何使用 a)。

var inputForm = 'Name:  <input type="text" id="nameinput" size="31" maxlength="31" tabindex="1" />' + '<input type="hidden" id="pinId" value="' + counter + '" />' + '<button id="inputButton">Submit</button>';

问题在于,在信息窗口气泡中,“隐藏”输入需要用户使用额外的 Tab。我在 SO 中阅读了建议使用 <div 的答案与 display: none但我不知道使用 <div在像我这样的变量中 inputForm .

如何删除不需要的标签?

编辑代码:

要测试此代码,请单击某处,然后会出现带有信息窗口的标记。在气泡内单击,然后使用 Tab 键可以看到气泡停在文本字段和“提交”按钮之间。

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<style type="text/css">
html { height: 100% }
body { height: 100%; margin: 0; padding: 0 }
#map-canvas { height: 100% }
</style>
<script type="text/javascript"
src="https://maps.googleapis.com/maps/api/js">
</script>
<script type="text/javascript">
var map;
var inwindow = new google.maps.InfoWindow();
var markers = [];
var counter = 0;

function initialize() {

var NY = new google.maps.LatLng(40.739112, -73.785848);
map = new google.maps.Map(
document.getElementById('map-canvas'), { center: NY, zoom: 16, mapTypeId: google.maps.MapTypeId.ROADMAP });

google.maps.event.addListener(map, 'click', function (event) {
addMarker(event.latLng);
});

google.maps.event.addListener(inwindow, 'domready', function () {
var button = document.getElementById('inputButton');
button.onclick = function() {
var input = document.getElementById('nameinput').value;
var id = parseInt(document.getElementById('pinId').value);
titleMarker(id, input);
inwindow.close();
};
});


function addMarker(location) {

counter++;

var inputForm = 'Name: ' + '<input type="text" id="nameinput" size="31" maxlength="31" tabindex="1" />' + '<input type="hidden" id="pinId" value="' + counter + '" tabindex="-1" />' + '<button id="inputButton">Submit</button>';

var marker = new google.maps.Marker({
position: location,
map: map,
draggable: true,
id: counter
});
inwindow.setContent(inputForm);
inwindow.open(map, marker);

markers.push(marker);

}

function titleMarker(markerId, markerTitle) {
for (var i=0; i<markers.length; i++) {
if (markers[i].id === markerId) {
markers[i].setTitle(markerTitle);
}
}
}



google.maps.event.addDomListener(window, "load", initialize);
</script>
</head>
<body>
<div id="map-canvas"/>
</body>
</html>

最佳答案

如果不希望元素被制表,将tabindex设置为-1,这会从tabindex中移除元素

var inputForm = 'Name:  ' +
'<input type="text" id="nameinput" size="31" maxlength="31" tabindex="1" />' +
'<input type="hidden" id="pinId" value="' + counter + '" tabindex="-1" />' +
'<button id="inputButton">Submit</button>';

关于javascript - 不在 <form> 中的隐藏 &lt;input&gt; 包含在 "tab"序列中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24499785/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com