我正在创建一个扩展搜索框,当它处于焦点上时,它会扩展并在离开焦点时收缩,但是我的页面中有许多按钮,文本框和单选按钮,当单击或聚焦时,其他与搜索框相同扩大和收缩。
The code I am using:
<script type="text/javascript" src="for admg/jquery-latest.min.js"></script>
<script type="text/javascript">
//global vars
var inputWdith = '150px';
var inputWdithReturn = '100px';
$(document).ready(function () {
$('input').focus(function () {
//clear the text in the box.
// $(this).val(function () {
// $(this).val('');
// });
//animate the box
$(this).animate({
width: inputWdith
}, 500)
});
$('input').blur(function () {
$(this).val(' Search ');
$(this).animate({
width: inputWdithReturn
}, 800)
});
});
</script>
最佳答案
与 $('input')
,您选择每种输入。给您的搜索框输入 id
或class
属性,例如<input id="searchBox" type="text" />
,然后使用 $('#searchBox')
选择它(或 $('.searchBox')
对于 class
属性)。
关于javascript - jQuery 代码应用于许多输入,但我只想将其应用于预期输入(搜索框)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6482426/