开发者

Will Javascript variables stay if I reset the form they are set from before I use them?

function gResults () {
    var TestVar = myform.inputbox.value;
    var url = TestVar;
    document.myform.reset();
   开发者_运维技巧     window.location=TestVar;
}

Assume a text box with a url in it.

Will that function always grab the form's input? Are the function's list of things always done in order and saved in memory? Or will the window.location always go to null?


Strings are pass by value. That script would correctly set window.location to equal myForm.inputbox.value from before it was reset.


url will get the value of TestVar at the time the line was executed, i.e. before the call to reset(), see this example.

But why would you reset the form if you're redirecting the page anyway?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜