html中的js代码怎么放进js文件中,格式
下面的代码是向注册表中写一个值,然后再读出来:<scripttype="text/javascript">functionaddItem(){varobj=newActi...
下面的代码是向注册表中写一个值,然后再读出来:
<script type="text/javascript">
function addItem() {
var obj = new ActiveXObject("WScript.Shell");
obj.RegWrite("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer\\TestValue", "1", "REG_SZ");
document.writeln("Written successfully</br>");
var testValue = obj.RegRead("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer\\TestValue");
document.writeln("Read successfully</br>");
document.writeln("The value of TestValue is "+testValue);
}
addItem(); //调用函数
</script>
这段代码在HTML网页中可以正常运行,但是我想保存在js文件中,直接运行(不通过网页)。应该怎么做?
试了一下,直接保存为.js文件会出错。 展开
<script type="text/javascript">
function addItem() {
var obj = new ActiveXObject("WScript.Shell");
obj.RegWrite("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer\\TestValue", "1", "REG_SZ");
document.writeln("Written successfully</br>");
var testValue = obj.RegRead("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer\\TestValue");
document.writeln("Read successfully</br>");
document.writeln("The value of TestValue is "+testValue);
}
addItem(); //调用函数
</script>
这段代码在HTML网页中可以正常运行,但是我想保存在js文件中,直接运行(不通过网页)。应该怎么做?
试了一下,直接保存为.js文件会出错。 展开
1个回答
展开全部
function addItem() {
var obj = new ActiveXObject("WScript.Shell");
obj.RegWrite("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer\\TestValue", "1", "REG_SZ");
document.writeln("Written successfully</br>");
var testValue = obj.RegRead("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer\\TestValue");
document.writeln("Read successfully</br>");
document.writeln("The value of TestValue is "+testValue);
}
保存为js文件,在html文件中写入代码<script type="text/javascript">
function addItem() {
var obj = new ActiveXObject("WScript.Shell");
obj.RegWrite("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer\\TestValue", "1", "REG_SZ");
document.writeln("Written successfully</br>");
var testValue = obj.RegRead("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer\\TestValue");
document.writeln("Read successfully</br>");
document.writeln("The value of TestValue is "+testValue);
}
保存为js文件,在html文件中写入代码包含js文件,并且在body中<body onload="addItem()">就可以了
var obj = new ActiveXObject("WScript.Shell");
obj.RegWrite("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer\\TestValue", "1", "REG_SZ");
document.writeln("Written successfully</br>");
var testValue = obj.RegRead("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer\\TestValue");
document.writeln("Read successfully</br>");
document.writeln("The value of TestValue is "+testValue);
}
保存为js文件,在html文件中写入代码<script type="text/javascript">
function addItem() {
var obj = new ActiveXObject("WScript.Shell");
obj.RegWrite("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer\\TestValue", "1", "REG_SZ");
document.writeln("Written successfully</br>");
var testValue = obj.RegRead("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer\\TestValue");
document.writeln("Read successfully</br>");
document.writeln("The value of TestValue is "+testValue);
}
保存为js文件,在html文件中写入代码包含js文件,并且在body中<body onload="addItem()">就可以了
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询