js之2016.8.7
2016-08-07 16:19
411 查看
<input type="text" name="textbox" value="荣耀8" data-default="荣耀8" style="width:80%;height:36px;border:none;" onclick="text_click(this);" onblur="text_blur(this);" />
<input type="button" value="搜 索" style="width:20%;height:36px;background:#01B3E1;border:none;float:right;" onclick="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;" onclick="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>
相关文章推荐
- XML + XSL + JS 构建小型Web App (十四)
- Node.js(day5)
- 给初学者提供几本学习js值得看的书
- XML + XSL + JS 构建小型Web App (十三)
- XML + XSL + JS 构建小型Web App (十)
- XML + XSL + JS 构建小型Web App (十一)
- XML + XSL + JS 构建小型Web App (十二)
- XML + XSL + JS 构建小型Web App (八)
- XML + XSL + JS 构建小型Web App (九)
- XML + XSL + JS 构建小型Web App (二)
- XML + XSL + JS 构建小型Web App (三)
- XML + XSL + JS 构建小型Web App (四)
- XML + XSL + JS 构建小型Web App (五)
- XML + XSL + JS 构建小型Web App (六)
- XML + XSL + JS 构建小型Web App (七)
- XML + XSL + JS 构建小型Web App (一)
- ASP+JS时的"""
- XML + XSL + JS 构建小型Web App (十五)
- 真正的 用JS 做的 loading
- JS版常见问题(二)兼容版本的无提示关闭窗口!