如果使用比較運算子:「==」、「!=」、「===」、「!==」,需要先使用「date.getTime()」,
例如:
var d1 = new Date(); var d2 = new Date(d1); var same = d1.getTime() === d2.getTime(); var notSame = d1.getTime() !== d2.getTime();
建立 Date 物件:
如果使用比較運算子:「==」、「!=」、「===」、「!==」,需要先使用「date.getTime()」,
例如:
var d1 = new Date(); var d2 = new Date(d1); var same = d1.getTime() === d2.getTime(); var notSame = d1.getTime() !== d2.getTime();
建立 Date 物件:
如果我已經取得form元素,要如何取得底下的tag呢?
var x = document.getElementById("myForm").elements.length;
語法:
formObject.elements
原來,要取得frame裡,頁面的元素,還要多一層寫法:
var ele = window.frames['frame_name'].document.getElementById('element_id');
參考:How can I get an element from within a frameset frame using JavaScript?
總結:
<a href="javascript: handler(); return false;">連結</a>
IE11 會對"return false;" 報錯...;還是先寫下面的好了...:
<a href="javascript:void(0)">連結</a>
1. 不能寫成 return(false);
2. 在 form tag 要加「return」。
<form action="index.jsp" method="post" onsubmit="return submitTest();">
form 表單,在送出前的事件。
window.onbeforeunload = confirmExit; function confirmExit() { return "You have attempted to leave this page. If you have made any changes to the fields without clicking the Save button, your changes will be lost. Are you sure you want to exit this page?"; }
For example, if the name of your form is ‘myform’, the JavaScript code for the submit call is:
document.forms["myform"].submit();
But, how to identify a form? Give an id attribute in the form tag