<input type="text" name="textbox" value="荣耀8" data-default="荣耀8" style="width:80%;height:36px;border:none;" οnclick="text_click(this);" οnblur="text_blur(this);" />
<input type="button" value="搜 索" style="width:20%;height:36px;background:#01B3E1;border:none;float:right;" οnclick="submit_click(this);" />
<script>
function text_click( txtSef ) {
if ( txtSef.value == txtSef.getAttribute( 'data-default' ) ) {
txtSef.value = '';
}
}
function text_blur( txtSef ) {
if ( txtSef.value == '' ) {
txtSef.value = txtSef.getAttribute( 'data-default' );
}
}
function text_focus( txtSef ) {
alert( '光标进来了' );
}
function submit_click( btSef ) {
var textbox = document.getElementsByName( 'textbox' )[ 0 ];
//if ( textbox.value == '' || textbox.value == textbox.getAttribute( 'data-default' )) {
if ( textbox.value == '' || textbox.value == getTextBoxDefaultValue( textbox ) ) {
alert( '请输入搜索内容' );
textbox.value = '';
textbox.focus();
return;
}
//alert( '您要搜索的内容为:' + textbox.value );
location = '/list.aspx?query=' + encodeURIComponent( textbox.value );
}
function getTextBoxDefaultValue( txtSef ) {
return txtSef.getAttribute( 'data-default' );
}
</script>
<input type="button" value="搜 索" style="width:20%;height:36px;background:#01B3E1;border:none;float:right;" οnclick="submit_click(this);" />
<script>
function text_click( txtSef ) {
if ( txtSef.value == txtSef.getAttribute( 'data-default' ) ) {
txtSef.value = '';
}
}
function text_blur( txtSef ) {
if ( txtSef.value == '' ) {
txtSef.value = txtSef.getAttribute( 'data-default' );
}
}
function text_focus( txtSef ) {
alert( '光标进来了' );
}
function submit_click( btSef ) {
var textbox = document.getElementsByName( 'textbox' )[ 0 ];
//if ( textbox.value == '' || textbox.value == textbox.getAttribute( 'data-default' )) {
if ( textbox.value == '' || textbox.value == getTextBoxDefaultValue( textbox ) ) {
alert( '请输入搜索内容' );
textbox.value = '';
textbox.focus();
return;
}
//alert( '您要搜索的内容为:' + textbox.value );
location = '/list.aspx?query=' + encodeURIComponent( textbox.value );
}
function getTextBoxDefaultValue( txtSef ) {
return txtSef.getAttribute( 'data-default' );
}
</script>