我需要一种确定的方法来弄清楚Javascript正在修改表单值?我能做的最好的是:
$(function(){
console.log($("input[name=Email]").val());
});
但是这个值的执行没有改变。
答案 0 :(得分:10)
在Chrome和Firefox中有一种新方法:console.trace
见这里:
https://developer.mozilla.org/en-US/docs/Web/API/console.trace
在网络检查员中:
> console.trace()
console.trace() VM251:2
(anonymous function) VM251:2
InjectedScript._evaluateOn VM223:581
InjectedScript._evaluateAndWrap VM223:540
InjectedScript.evaluate VM223:459
undefined
所以要修改接受的答案:
$('input#myInputAbove').change(function(){
console.trace(); // No breakpoint needed anymore.
});
答案 1 :(得分:2)
将其直接插入要跟踪的表单元素的HTML下方:
$('input#myInputAbove').change(function(){
console.log('change detected'); // Breakpoint on this line
});
使用FireBug将breakpoint插入上述JS方法中。点击它然后看看堆栈跟踪。
答案 2 :(得分:1)
以下内容将向您展示哪些事件处理程序已绑定到元素:
$.each($("input[name='Email']").data('events'), function(i, event){
$.each(event, function(i, handler){
console.log( handler.handler );
});
});
答案 3 :(得分:-1)
prev_value = document.getElementByName('Email').value;
$("input[name=Email]").change(function(){
var cur_value = document.getElementById('Email').value;
if(cur_value != prev_value){
alert("Value changed");
//or console.log("Value changed");
}
}