在下面的代码中,如何在正文中的字段中正确插入testName函数initialize()中定义的val Name?
<html>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.6.min.js"></script>
<script type="text/javascript">
function intialize()
{
var testName="John";
}
</script>
</head>
<body onload="intialize()">
<input id="Name" type="textbox" value=testName>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
Mar*_*ein 11
您可以使用文档准备:
<html>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.6.min.js"></script>
<script type="text/javascript">
$(function(){
$('#Name').val('testName');
});
</script>
</head>
<body>
<input id="Name" type="textbox" value=""/>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
使用id,Name,并在文档准备好后将值设置为'testName'.
| 归档时间: |
|
| 查看次数: |
56261 次 |
| 最近记录: |