版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/taozhe666/article/details/75333249
1.JS中判断null、undefined与NaN的方法
判断undefined
<span style="font-size: small;">var tmp = undefined;
if (typeof(tmp) == "undefined"){
alert("undefined");
}</span>
typeof 返回的是字符串,有六种可能:"number"、"string"、"boolean"、"object"、"function"、"undefined"
判断null
<span style="font-size: small;">var tmp = null;
if (!tmp && typeof(tmp)!="undefined" && tmp!=0){
alert("null");
} </span>
判断NaN
<span style="font-size: small;">var tmp = 0/0;
if(isNaN(tmp)){
alert("NaN");
}</span>
2.Jquery怎么获取select选中项 自定义属性的值
emoney是自定义属性
$("#ddl").find("option:selected").attr("emoney");
3.type=submit 提交的时候,想先判断后再提交,可用return doSubmit,返回false,则中断提交。
<input class="submit" id="btnSet" type="submit" value="设置" onclick="return doSubmit()"/>