<!DOCTYPE html>
<html>
<head>
<title></title>
<script type="text/javascript">
function fiction()
{
shohai.javat.focus();
}
</script>
</head>
<body>
<form name="shohai">
<input type="text" name="javat" placeholder="this is the text" >
<br>
<br>
<input type="text" name="kamel" placeholder="this is the text 2" onblur="fiction2()">
<br>
<br>
<button onclick="fiction()">Aceptar</button>
</form>
</body>
</html>
谢谢你回答我。
我正在尝试集中java输入,它可以工作,但立即失去他的位置。为什么?
我在网上搜索了运气不好。
答案 0 :(得分:1)
嗯,在我看来,当你按下&#34; Aceptar&#34;按钮,输入确实对焦,但表单也提交,有效地重新加载页面,并给人以焦点丢失的印象。这是因为没有任何<button>
属性的type
标记将默认为submit
。因此,只需在标记中添加type="button"
,即<button type="button">
。
该更改的完整代码:
<form name="shohai">
<input type="text" name="javat" placeholder="this is the text" >
<br>
<br>
<input type="text" name="kamel" placeholder="this is the text 2" onblur="fiction2()">
<br>
<br>
<button type="button" onclick="fiction()">Aceptar</button>
</form>
和其他用户一样,目前还不是很清楚你想做什么。你想要&#34; Aceptar&#34;要...提交表格或只关注输入?您无法同时提交和关注(很好,您可以,但提交表单会重新加载整个页面)。而且通过DOM方法识别你的元素也是一个更好的主意,说实话,我甚至不知道你可以做shohai.javat
。