js设置输入框失去光标与光标选中时样式

时间:2023-01-22 22:34:20

输入框样式

<script language="javascript" type="text/javascript">

function glb_searchTextOnfocus(obj) {

if (obj.value == '请输入您想要的作品...')

obj.value = '';

obj.style.color = '#333';

}

function glb_searchTextOnBlur(obj) {

if (obj.value == '') {

obj.value = '请输入您想要的作品...';

obj.style.color = '#98BC00';

} else {

obj.style.color = '#333';

}

}

</script>

<input name="q" type="text" class="searchkey " value="请输入您想要的作品..." onfocus="glb_searchTextOnfocus(this);"  onblur="glb_searchTextOnBlur(this);" maxlength="70" />