我正在创建一个正在扩展的搜索框,当它聚焦时,它会被扩展,当它离开聚焦时会收缩,但我的页面中有很多按钮、文本框和单选按钮,当点击或聚焦时,其他相同的搜索框会被扩展和收缩。
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
属性)进行选择。
如果您的searchbox是这样的aspnet控件。
<asp:TextBox runat="server" ID="texbox"></asp:TextBox>
那么正确的选择器应该是这样的:
$('#<%=texbox.ClientID %>')
希望它能帮助