8:05 2010-1-13 --------------------------- jsp: ==================================================================== <form id="inputAgeForm" onsubmit="setAction(this)"> <input type="text" name="inputAge" id="txt_inputAge" value="555" /> <input type="submit" value="提交" /> </form> js: ==================================================================== // JavaScript Document // =============================================== // 设置输入表单的“Action”属性。 // =============================================== function setAction( inputAgeForm ) { // ------------------------------------------------- // 尽量把控件做为参数传过来,以免在改名后产生错误。 // ( By Livon 2010-01-13 ) // ------------------------------------------------- //inputAgeForm.action = g_context_path + "/howOldResultAction.do"; // ------------------------------------------------- // 使用“with”方法,让代码更简洁。 // 适用于重复较多的地方。 // ( By Livon 2010-01-13 ) // ------------------------------------------------- //with( inputAgeForm ) //{ // action = g_context_path + "/howOldResultAction.do"; //} // ------------------------------------------------- // 使用“setArrtubut”方法,语意表述更直观。 // ( By Livon 2010-01-13 ) // ------------------------------------------------- with( inputAgeForm ) { setAttribute("action",g_context_path + "/howOldResultAction.do"); } }