查找更改< input />的值属性的脚本标签 [英] Find script that changed the value attribute of a <input /> tag
问题描述
<form id="search" action="/search" method="get" autocomplete="off">
<div>
<input type = "button" name = 'test_button" value = "test" />
</div>
</form>
<script>
document.getElementById("test_button").value = "changed_test"
</script>
正如上面的HTML代码所示,我已经定义了一个名为 test_button
的按钮,并且值 test
并使用脚本标记中的代码更改它的值。
Just as the HTML code above shows, I have defined a button with name test_button
and value test
and changing it's value with the code in the script tag.
现在我正在调试一个使用Firebug和类似这样的机制的大型网页Linux中的Firefox。
Now I am debugging a large webpage which is using a mechanism like this using Firebug and Firefox in Linux.
我想知道如何找到更改值
属性的脚本< input ... />
,但网页太大,各种< script>
并且匿名自动执行的函数几乎不可能手动找到特定的脚本
。
I want to know how I can find the script that changes the value
attribute of the <input ... />
, but the web page is too large, various <script>
and anonymous functions which is auto-executed made it nearly impossible to find the specific script
manually.
因为我在Linux中,我不能使用任何Microsoft工具整理整个网页。我只有Firebug和Chrome。 Firebug能意识到吗?有没有人知道如何找到更改值
的特定< script>
?
Since I am in Linux, I cannot use any Microsoft tools to search the whole web page. I only have Firebug and Chrome. Can Firebug realize that? Does anyone have a good idea how to find the specific <script>
that changed the value
?
推荐答案
使用按钮在表单后面添加这样的代码到这个文档:
Add some code like this to the document, right after the form with the button:
<script>
var node = document.getElementById("test_button");
Object.defineProperty(node, 'value', {
set: function() { throw new Error('button value modified'); }
});
</script>
当有任何东西试图修改按钮的值时,这会抛出错误
。
This will throw an error when anything tries to modify the button's value
.
展开错误并单击显示的最后一个行号。这将直接转到设置按钮值的行。
Expand the error and click the last line number shown. This will take you straight to the line that set the value of the button.
这是一个演示: http://jsfiddle.net/XSJZN/
在Chrome 17中测试。
Tested in Chrome 17.
这篇关于查找更改< input />的值属性的脚本标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!