想做一个类似淘宝的搜索框,就是点击上面的不同文字,文本框出现相应的说明,然后点击文本框,里面的字消失。输入内容后,再次点击,里面的字不消失了,还有就是,本来的字是灰色的,自己输入的字是黑色的。
我的代码:
<script language="JavaScript" type="text/javascript">
function input(sname){
if(sname=="sale"){
document.getElementById("text").value="输入书名或ISBN找到你要卖的书登记即可。";
document.getElementById("sale").style.background="url(images/imc-04.gif)";
document.getElementById("borrow").style.background="";
document.getElementById("buy").style.background="";
}
else if(sname=='borrow'){
document.getElementById("text").value="输入书名或ISBN找到你要jie书登记即可!";
document.getElementById("sale").style.background="";
document.getElementById("borrow").style.background="url(images/imc-04.gif)";
document.getElementById("buy").style.background="";
}
else if(sname=='buy'){
document.getElementById("text").value="输入书名或ISBN找到你要mai书登记即可!";
document.getElementById("sale").style.background="";
document.getElementById("borrow").style.background="";
document.getElementById("buy").style.background="url(images/imc-04.gif)";
}
}
</javascript>
<body>
<div id="menu">
<a href="#" class="png" id="sale" onclick="input('sale')" style="background:url(images/imc-04.gif)"><img src="images/sale.png"></a>
<a href="#" class="png" id="borrow" onclick="input('borrow')"><img src="images/borrow.png"></a>
<a href="#" class="png" id="buy" onclick="input('buy')"><img src="images/buy.png"></a> </div><div id="search">
<form>
<input type="text" class="text" id="text" value="输入书名或ISBN找到你要卖的书登记即可。" onFocus="if(value==defaultValue){value='';}" onBlur="if(!value){value=defaultValue;}" /></form>
</body>这个只能在点sale这个链接的时候 消失文字,其他的不行,自己输入的字也不会变黑色。(代码不全,主要就是这个样字)
请教高手了!!!
我的代码:
<script language="JavaScript" type="text/javascript">
function input(sname){
if(sname=="sale"){
document.getElementById("text").value="输入书名或ISBN找到你要卖的书登记即可。";
document.getElementById("sale").style.background="url(images/imc-04.gif)";
document.getElementById("borrow").style.background="";
document.getElementById("buy").style.background="";
}
else if(sname=='borrow'){
document.getElementById("text").value="输入书名或ISBN找到你要jie书登记即可!";
document.getElementById("sale").style.background="";
document.getElementById("borrow").style.background="url(images/imc-04.gif)";
document.getElementById("buy").style.background="";
}
else if(sname=='buy'){
document.getElementById("text").value="输入书名或ISBN找到你要mai书登记即可!";
document.getElementById("sale").style.background="";
document.getElementById("borrow").style.background="";
document.getElementById("buy").style.background="url(images/imc-04.gif)";
}
}
</javascript>
<body>
<div id="menu">
<a href="#" class="png" id="sale" onclick="input('sale')" style="background:url(images/imc-04.gif)"><img src="images/sale.png"></a>
<a href="#" class="png" id="borrow" onclick="input('borrow')"><img src="images/borrow.png"></a>
<a href="#" class="png" id="buy" onclick="input('buy')"><img src="images/buy.png"></a> </div><div id="search">
<form>
<input type="text" class="text" id="text" value="输入书名或ISBN找到你要卖的书登记即可。" onFocus="if(value==defaultValue){value='';}" onBlur="if(!value){value=defaultValue;}" /></form>
</body>这个只能在点sale这个链接的时候 消失文字,其他的不行,自己输入的字也不会变黑色。(代码不全,主要就是这个样字)
请教高手了!!!
解决方案 »
- 一个利用js对select下拉框做出动态显示效果的问题,求助多人均不会,希望能在这里得到答案
- 使用confirm确认框时希望将焦点默认在取消按钮上
- mysql query browser中加数据
- 高分求解,json.js的问题。(急)
- 我想看看无满意结帖是怎么回事
- 我是用window.open() 来打开一个页面 我现在如何实现不用openDialog() 来实现重复点击只弹出一个页面
- 求检测最后一个字符不能为“,”,谢谢回答~
- 请问怎样实现在类似优酷打开视频页面的效果 只打开一个新窗口 再打开其他的视频页面 也只在第一次打开的新窗口更新链接地址
- 新年礼物:小游戏(1),答对着得150分,参与者也有分!答案最简单者得高分![IE6实现即可] [请进……]
- Java代码抓取页面显示的内容保存为图片
- google浏览器的blendTrans错误,在ie一切正常
- 关于js中正则表达式的替换问题,急求解决
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title> <script language="JavaScript" type="text/javascript">
var userInputText='';
var defaultSaleTxt = "输入书名或ISBN找到你要卖的书登记即可。";
var defaultBorrowTxt = "输入书名或ISBN找到你要jie书登记即可!";
var defaultBuyTxt = "输入书名或ISBN找到你要mai书登记即可!"; function input(sname) {
if (sname == "sale") {
if (userInputText.length > 0) {
document.getElementById("text").value = userInputText;
}
else {
document.getElementById("text").value = defaultSaleTxt;
}
document.getElementById("sale").style.background = "url(images/imc-04.gif)";
document.getElementById("borrow").style.background = "";
document.getElementById("buy").style.background = "";
}
else if (sname == 'borrow') {
if (userInputText.length > 0) {
document.getElementById("text").value = userInputText;
}
else {
document.getElementById("text").value = defaultBorrowTxt;
}
document.getElementById("sale").style.background = "";
document.getElementById("borrow").style.background = "url(images/imc-04.gif)";
document.getElementById("buy").style.background = "";
}
else if (sname == 'buy') {
if (userInputText.length > 0) {
document.getElementById("text").value = userInputText;
}
else {
document.getElementById("text").value = defaultBuyTxt;
}
document.getElementById("sale").style.background = "";
document.getElementById("borrow").style.background = "";
document.getElementById("buy").style.background = "url(images/imc-04.gif)";
}
}
</script> <style type="text/css">
.text
{
color: gray;
font-size: 11px;
font-style: oblique;
}
.searchText
{
font-size: 11px;
}
</style>
</head>
<body>
<div id="menu">
<a href="#" class="png" id="sale" onclick="input('sale')" style="background: url(images/imc-04.gif)">Sale</a>
<a href="#" class="png" id="borrow" onclick="input('borrow')">Borrow</a>
<a href="#" class="png" id="buy" onclick="input('buy')">Buy</a>
</div>
<div id="search">
<form>
<input type="text" class="text" id="text" value="输入书名或ISBN找到你要卖的书登记即可。" onfocus="if(value==defaultValue){value='';this.className='searchText';userInputText='';}else{this.className='searchText';userInputText=value;}"
onblur="if(!value){value=defaultValue;this.className='text';userInputText='';}else{this.className='searchText';userInputText=value;}" /></form>
</body>
</html>
第一次点击之后字是消失了,但是点了borrow 和 buy 后,再点input 字不消失的啊,而且都变黑了。还是不懂呜呜呜
//layer demo
var layer={
inint:function (){},
seashowtip: function(tips,flag,iwidth){
var my_tips=document.all.mytips;
e=window.event || event;
var mouseX=e.pageX || e.clientX;
var mouseY=e.pageY || e.clientY;
if(flag){
my_tips.innerHTML=tips;
my_tips.style.display="";
my_tips.style.width=iwidth;
my_tips.style.left=mouseX+10+document.body.scrollLeft;
my_tips.style.top=mouseY+10+document.body.scrollTop;
}
else
{
my_tips.style.display="none";
}
}//onmousemove=seashowtip(this.tips,1,150) onmouseout=seashowtip(this.tips,0,150)
}
<input name="demo" type="text" size="15" tips="请输入内容" onmousemove=seashowtip(this.tips,1,100) onmouseout=seashowtip(this.tips,0,100)/ >
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title> <script language="JavaScript" type="text/javascript">
var userInputText='';
var info = {
defaultSaleTxt : "输入书名或ISBN找到你要卖的书登记即可。",
defaultBorrowTxt : "输入书名或ISBN找到你要jie书登记即可!",
defaultBuyTxt : "输入书名或ISBN找到你要mai书登记即可!"
};
var $ = function(id){return document.getElementById(id)};
function input(sname) {
var input = $("text");
if (sname == "sale") {
$("sale").style.background = "url(images/imc-04.gif)";
$("borrow").style.background = "";
$("buy").style.background = "";
}
else if (sname == 'borrow') {
$("sale").style.background = "";
$("borrow").style.background = "url(images/imc-04.gif)";
$("buy").style.background = "";
}
else if (sname == 'buy') {
$("sale").style.background = "";
$("borrow").style.background = "";
$("buy").style.background = "url(images/imc-04.gif)";
}
sname = sname.replace(sname.charAt(0),sname.charAt(0).toUpperCase());
var textStr = info["default" + sname + "Txt"];
if (userInputText.length > 0) {
input.value = userInputText;
}
else {
input.value = textStr;
}
input.onfocus = function(){
if(this.value==textStr){
this.value='';
this.className='searchText';
userInputText='';
}else{
this.className='searchText';
userInputText=this.value;
}
};
input.onblur = function (){
if(!this.value){
this.value=textStr;
this.className='text';
userInputText='';
}else{
this.className='searchText';
userInputText=this.value;
}
};
}
window.onload = function(){
input("sale");
};
</script> <style type="text/css">
.text
{
color: gray;
font-size: 11px;
font-style: oblique;
}
.searchText
{
font-size: 11px;
}
</style>
</head>
<body>
<div id="menu">
<a href="#" class="png" id="sale" onclick="input('sale')" style="background: url(images/imc-04.gif)">Sale</a>
<a href="#" class="png" id="borrow" onclick="input('borrow')">Borrow</a>
<a href="#" class="png" id="buy" onclick="input('buy')">Buy</a>
</div>
<div id="search">
<form>
<input type="text" class="text" id="text" size="50" /></form>
</body>
</html>楼主这样行吗?