日期:2014-05-16  浏览次数:20304 次

为什么我这段代码无法改变value的内容?
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style type="text/css">
.form_text_search_keyword {
border-style: none;
float: right;
background-image: url(form_text_search_keyword.jpg);
width: 200px;
height: 200px;
font-size: 18px;
}
</style>
<style type="text/javascript">
function formkcus(x){
document.getElementById(x).value="aaa"
}
</style>
</head>

<body style="background:#3CF">
<form action="mylist.php" method="get">
  <input type="text" id="forddword" class="form_text_search_keyword" name="search" autocomplete="on" value="请输入关键字" onfocus="formkcus(this.id)">
</form>
</body>
</html>
JavaScript input text value onfocus

------解决方案--------------------
囧,你包含js的代码怎么是<style>?????
<style type="text/javascript">
function formkcus(x){
document.getElementById(x).value="aaa"
}
</style>

改成<script>
------解决方案--------------------
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style type="text/css">
.form_text_search_keyword {
border-style: none;
float: right;
background-image: url(form_text_search_keyword.jpg);
width: 200px;
height: 200px;
font-size: 18px;
}

</style>
<script>
function formkcus(x){
   document.getElementById(x).value="aaa";
}
</script>
</head>

<body style="background:#3CF">
<form action="mylist.php" method="get">
  <input type="text" id="forddword" class="form_text_search_keyword" name="search" autocomplete="on" value="请输入关键字" onfocus="javascript:formkcus(this.id)">
</form>
</body>
</html>