gpt4 book ai didi

javascript - 如何在有输入时禁用搜索框的转换?

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

我不确定如何进一步描述这一点,如果很难理解我想说的话,我深表歉意。你好,首先我想道歉,因为我是新手。我想知道是否有可能确保代码片段中的搜索框在我输入一些单词后不发生变化。换句话说,它不会返回其原始状态当有输入时是一个圆圈。先感谢您!

body {
margin: 0;
padding: 0;
font-family: Century Gothic, sans-serif;
}

.displayNavigation input[type="search"],
.displayNavigation textarea {
border: 1px solid grey;
border-radius: 20px;
border-bottom: 1px solid grey;
background: transparent;
outline: none;
height: 25px;
color: autoselect;
font-size: 16px;
}

.displayNavigation {
padding: 0 0 10px 0;
transition: .4s;
display: block;
border-collapse: collapse;
margin-bottom: 3px;
}

table {
margin-top: 50px;
margin-left: 50px;
}

.search-box {
position: absolute;
transform: translate(-7%, -25%);
background: -moz-linear-gradient(top, #87a5ca, #144989);
background: -webkit-gradient(linear, 0 10, 0 85%, from(#407ac0), to(#144989));
height: 40px;
border-radius: 40px;
padding: 4px;
margin-top: 5px;
margin-left: 25px;
font-family: Century Gothic;
sans-serif;
cursor: pointer;
}

.search-box:hover>.search-txt {
width: 240px;
padding: 0 6px;
}

.search-box:hover>.search-btn {
background: #e0e9f3;
}

.search-btn {
color: #e84118;
float: right;
width: 40px;
height: 40px;
border-radius: 50%;
background-color: #144989;
display: flex;
justify-content: center;
align-items: center;
cursor: pointer;
transition: .4s;
border: none;
}

.search-txt {
border: none;
background: none;
outline: none;
float: left;
padding: 0px;
color: white;
font-size: 15px;
transition: .4s;
line-height: 40px;
width: 0px;
}

::placeholder {
color: rgba(255, 255, 255, .35);
font-size: 15px;
font-family: Century Gothic, sans-serif;
}
<html>

<head>
<title>Search-Box</title>
</head>

<body>
<table class="displayNavigation" align="center">
<form method="POST" action="Search_Teachers.php">
<td class="search-box">
<input autocomplete="off" name="Search" class="search-txt" type="text" placeholder="Search...">
<button class="search-btn" href="#"><img src ='Icons/search_blue.png' height ='27px' width ='27px'></button>
</td>
</table>
</form>
</body>

</html>

最佳答案

在您的输入中,您可以添加类似 id 和 required 的内容,如下所示:

<input id=someInput  autocomplete="off" name="Search" class="search-txt" type="text" placeholder="Search..." required>

在你的 CSS 中添加:

#someInput: :valid { width: 240px;}

然后用 invalid 做你想做的:

#someInput :invalid { what you want}

测试成功,祝你好运!

关于javascript - 如何在有输入时禁用搜索框的转换?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51274542/

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