为什么这段javascript不能进行相应的功能呢?
<html><head>
<script language="JavaScript" type="text/javascript">
var str = "please";
var content = document.form1.content.value;
function getFocus() {if(content==str) {content = ''}}
function lostFocus() {if( content=''){content = str}}
</script></head>
<body>
<form id="form1">
<input name="content" onblur="lostFocus();" onfocus="getFocus()" type="text" value="please" size="25">
</form>
</body>
</html>
<html><head>
<script language="JavaScript" type="text/javascript">
var str = "please";
var content = document.form1.content.value;
function getFocus() {if(content==str) {content = ''}}
function lostFocus() {if( content=''){content = str}}
</script></head>
<body>
<form id="form1">
<input name="content" onblur="lostFocus();" onfocus="getFocus()" type="text" value="please" size="25">
</form>
</body>
</html>
解决方案 »
- js中display为block时获取不到
- 隐藏table中的一行,在火狐和谷歌中正确,在ie中失败
- 求 兼容FF的类似猫扑框架代码
- 有段很低级的JS代码,大家帮看看!!!错在哪儿
- 大家帮帮我看下这我的菜单问题,要哭了..----------------!
- 帮我全面解释下面的javascript实例!!!(具体到每句都表示的意思)
- 编辑框值为0时,按钮不可用,>0时按钮可用,怎样实现?
- 做可视化编辑器用什么事件监控到iframe.docment内容的变化
- 如何取背景色?
- 各位高手兼大虾帮我看看这段程序,有问题,如何修改?
- 如何使用JS 向Iframe的文本框中写入一个字符
- 请教一下各位单选(radio)按钮取值的问题,谢谢!!
改成
function lostFocus() {if( content==''){content = str}}
<html><head>
<script language="JavaScript" type="text/javascript">
var str = "please";
function getFocus(input) {if(input.value) {input.value = ''}}
function lostFocus(input) {if(!input.value){input.value = str}}
</script></head>
<body>
<form id="form1">
<input name="content" onblur="lostFocus(this);" onfocus="getFocus(this)" type="text" value="please" size="25">
</form>
</body>
</html>
<script language="JavaScript" type="text/javascript">
var str = "please";
function getFocus(input) {if(input.value == str) {input.value = ''}}
function lostFocus(input) {if(input.value == ""){input.value = str}}
</script></head>
<body>
<form id="form1">
<input name="content" onblur="lostFocus(this);" onfocus="getFocus(this)" type="text" value="please" size="25">
</form>
</body>
</html>
点击后please消失,开始你的输入
请看这个页面顶部 搜索按钮 旁边的 输入框 就是这个效果
http://topic.csdn.net/u/20100624/10/a1e13308-e6ab-4e5a-a89e-4ed918e8a78a.html?seed=849730198&r=66469015#r_66469015
lihui_shine的代码?什么逻辑?
我这就来解释回复此帖<html><head>
<script language="JavaScript" type="text/javascript">
var str = "please";
function getFocus(obj){if(obj.value==str) {obj.value = ''}}
function lostFocus(obj){if(obj.value==''){obj.value = str}}
</script></head>
<body>
<form id="form1">
<input name="content" onblur="lostFocus(this);" onfocus="getFocus(this)" type="text" value="please" size="25">
</form>
</body>
</html>