0
我想在javascript中获取我的文本框的值。这是我的Javascript成为document.getElementById('TextBox1')。value is not working
<script type="text/javascript">
var submitted = false; var type;
window.onbeforeunload = function() {
if (!submitted) {
return "Are you sure you want to leave this page, your test will not be saved?"+type;
}
};
document.getElementById('form1').onsubmit = function() {
type=document.getElementById('TextBox1').value;
submitted = true;
};
</script>
不管我输入什么,如果你想显示的警告框类型的值,那么,如果改变(它不给我TextBox1的
文本框在哪里? –
如果您的代码*来自HTML源代码中的元素,它将无法工作。将'
这看起来只是一个逻辑问题:
当你运行
onsubmit
,它设置submitted
为true,然后运行onbeforeunload
。现在它基本上只会返回输入值,如果你还没有运行onsubmit
。如果您从(!submitted)
中取出!
,它会为您提供输入值的警报。来源
2016-03-04 18:37:33 SeattleFrey