字符串和函数的名称相同
Same name for a string and a function
现在我的大脑放屁很大。我有这个功能:
function uplodeVirus(){
console.log('working')
console.log('uplodeVirus')
var form = document.getElementsByTagName('form')[1]
console.log(form)
var select = form.children[0]
console.log(select)
for (x in select) {
var lN = select[x].innerHTML // var linkName
if (lN == "vspam 0.3 [OpenRelay-backdoor.vspam ] (0.003 Gb)"){
value = select[x].value
select[x].setAttribute("selected", "selected");
form.submit()
break
}
}
}
别担心,这不是真正的病毒!!!这是一个名为slave hack的游戏机器人-用于学习目的
不管怎样,当我调用函数时:
var ip = '2.2.2.2'
var uplodeVirus = 'http://www.slavehack.com/index2.php?page=internet&var2=' + ip + '&var3=files&aktie=upload'
var currentUrl = window.location.href
console.log(currentUrl)
console.log(uplodeVirus)
if (currentUrl == uplodeVirus) { //Yes, I made sure that currentUrl = uplodeVirus
uplodeVirus()
}
什么都没发生。。。但如果我把代码从函数中取出,然后这样做:
if (currentUrl == uplodeVirus){
console.log('working')
console.log('uplodeVirus')
var form = document.getElementsByTagName('form')[1]
console.log(form)
var select = form.children[0]
console.log(select)
for (x in select) {
var lN = select[x].innerHTML // var linkName
if (lN == "vspam 0.3 [OpenRelay-backdoor.vspam ] (0.003 Gb)"){
value = select[x].value
select[x].setAttribute("selected", "selected");
form.submit()
break
}
}
}
它有效!!!现在,我可以选择B,但我真的想弄清楚我做错了什么。
提前感谢!
您使用相同名称命名URL变量和函数:uplodeVirus
由于在尝试调用函数之前,变量已初始化为包含字符串,因此调用uplodeVirus()
与调用("")()
相同。这没有任何意义,因为字符串不是函数。
请尝试更改其中一个的名称。
相关文章:
- 如何在JavaScript中将字符串转换为函数引用
- jQuery中是否内置了任何字符串格式化函数
- JavaScript按钮/输入/函数,字符串反转
- 推荐在JavaScript中执行存储为字符串的函数,而不是使用eval
- 从带参数的字符串变量调用函数中的函数
- 是否可以像字符串一样/操作/函数
- 从字符串调用javascript函数
- jquery字符串变量上的每个函数
- 如何在只接受字符串值/文字的HTML属性中调用函数
- 将JSON字符串转换为函数参数
- 在Javascript中将字符串转换为函数
- 正在创建使用子字符串解析JSON数据的函数
- 是否可以在 ng-click 中调用函数字符串
- 用于查找函数字符串 javascript 的正则表达式
- Regex js解析函数字符串
- 是传递给函数(字符串或对象)的元素
- 如何在不使用eval()的情况下将完整的函数字符串转换为javascript函数
- javascript函数字符串slice
- 引用函数(字符串)javascript中的数组项
- JS regex从一个函数字符串中提取多行参数