将变量名添加到HTML标记中
Add variable name to HTML Markups
下面的VBScript使用来自输入对话框的输入生成两个文件。下面我想将文件名(fileName
)添加到以下脚本创建的JavaScript文件中的document.write('Confirm file"&filename&" completed');
中。
但是当我这样做时,它会像上面写的那样以引号括起来的变量名返回,而不是变量本身。我知道这和引言有关,但我不知道该怎么做。任何帮助都会很感激。
fileName=InputBox("Enter a Name for the new SubRoutine: ","Enter Value","NewRoutine")
CreateFolder
CreateHTML
CreateJS
Sub CreateHTML
Set objFS = CreateObject("Scripting.FileSystemObject")
Set objNewFile = objFS.CreateTextFile(fileName&"'"&fileName&".html")
objNewFile.WriteLine "<html>"
objNewFile.WriteLine "<head>"
objNewFile.WriteLine "<title>Created by Robot--MM</title>"
objNewFile.WriteLine "</head><body>"
objNewFile.WriteLine "<script type='text/javascript' src='"&fileName&".js'></script>"
objNewFile.WriteLine "<script>"&fileName&"()</script>"
objNewFile.WriteLine "</body>"
objNewFile.WriteLine "</html>"
objNewFile.Close
End Sub
Sub CreateJS
Set objFS = CreateObject("Scripting.FileSystemObject")
fileName2 = fileName & ".js"
Set objNewFilejs = objFS.CreateTextFile(fileName&"'"&fileName&".js")
objNewFilejs.WriteLine "var "&fileName&" = function() { window.alert('Hi,This is an alert from the file : "&fileName2&"');"
objNewFilejs.WriteLine "document.write('Confirmed file loaded.'); }"
objNewFilejs.Close
End Sub
Sub CreateFolder
Set objShell = CreateObject("Wscript.Shell")
strPath = Wscript.ScriptFullName
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.GetFile(strPath)
strFolder = objFSO.GetParentFolderName(objFile)
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.CreateFolder(strFolder & "/"&fileName)
objShell.Run objFolder
Set Sh = Nothing
End Sub
我做了一个简化的回答。我意识到我把引语放错地方了。这里有一些升级的解决方案。
fileName = InputBox("Please enter a name for your new files:", _"Create File")
US = CreateObject("WScript.Shell").ExpandEnvironmentStrings("%UserProfile%")
Sub CreateHTML
Set objFS = CreateObject("Scripting.FileSystemObject")
Set objNewFile = objFS.CreateTextFile(US &"'Desktop'"& fileName&".html")
objNewFile.WriteLine "<html>"
objNewFile.WriteLine"<link rel = 'stylesheet' href='"&fileName&".css'>"
objNewFile.WriteLine "<head>"
objNewFile.WriteLine "<title>Created by Robot--MM</title>"
objNewFile.WriteLine "</head><body>"
objNewFile.WriteLine "<script type='text/javascript' src='"&fileName&".js'></script>"
objNewFile.WriteLine "<script> "&fileName&"()""</script>"
objNewFile.WriteLine "</body>"
objNewFile.WriteLine "</html>"
objNewFile.Close
End Sub
CreateHTML
Sub CreateJS
Set objFS = CreateObject("Scripting.FileSystemObject")
Set objNewFilejs = objFS.CreateTextFile(US &"'Desktop'"& fileName&".js")
objNewFilejs.WriteLine "window.alert('Hi,This is an alert from the file ');"
objNewFilejs.WriteLine "document.write('Document loaded')"
objNewFilejs.Close
End Sub
CreateJS
Sub CreateCSS
Set objFS = CreateObject("Scripting.FileSystemObject")
Set objNewFileCSS = objFS.CreateTextFile(US &"'Desktop'"& fileName&".css")
objNewFilecss.WriteLine "body {text-align:center;font-family:'Zapfino',serif;}"
objNewFilecss.Close
End Sub
CreateCSS
相关文章:
- AngularJS-在JSON选择器中使用变量名
- 命令行中的Uglify js;不要弄乱变量名
- 像createComment这样的各种自定义变量名在内联javascript中被覆盖,但在外部js中没有.为什么?
- 这在JavaScript中是一个好的变量名吗
- 将html变量从Ajax传递到PHP
- html类名中的数字形式的Javascript变量值
- 在JavaScript中使用HTML变量
- 在javascript中,在变量名之前使用var有什么区别/优势吗
- 在Javascript中连接一个动态变量名
- 如何使用jQuery循环变量名
- JavaScript将字符串转换为变量名
- 根据发送到javascript中函数的参数创建变量名
- 检索本身包含变量的 Jquery 变量名的值
- 从 Rails dom_id 方法获取 HTML 类名
- 测试JavaScript是否符合异常变量名
- ng绑定html,变量名来自ng repeat,但在其他地方定义了变量
- HTML元素呈现为变量名
- 将变量名添加到HTML标记中
- 我们可以在html中有变量名,jQuery
- 从HTML网站检索变量名