Javascript的Date.getMonth()方法:
會依據當地時間來傳回日期物件中的月份,傳回值是一個0到11的正整數,0代表一月。
由於回傳數值不是1~12,處理時要記得+1。
2019年8月26日 星期一
2016年11月23日 星期三
JavaScript如何取得Select選項中的値
在變數sampleValue中取得Select目前選項的Value
<!DOCTYPE html>
<html>
<body>
<select id="sample">
<option>Test 1</option>
<option>Test 2</option>
<option>Test 3</option>
<option>Test 4</option>
</select>
<button onclick="myTest()">Try it</button>
<p id="test"></p>
<script>
function myTest() {
var sampleValue = document.getElementById("sample").value;
document.getElementById("test").innerHTML = sampleValue;
}
</script>
</body>
</html>
2016年11月22日 星期二
JavaScript/Jquery簡單判斷undefined
var test = undefined;
if (typeof(test) == "undefined")
{
alert("undefined");
}
typeof 返回有六種可能:"number"、"string"、"boolean"、"object"、"function"、"undefined"
2016年11月16日 星期三
ASP MVC結構下,如何在.js中讀取Web.config
- 在Web.config中放入需要讀取的值,例如123456。
- 在對應.js的.cshtml中放入。
- 最後是.js中讀取值123456,在這裡使用彈出視窗顯示。
<appsettings>
<add key="testjsget" value="123456"></add>
</appsettings>
var js =
{
get: '@System.Configuration.ConfigurationManager.AppSettings["testjsget"]'
};
alert(js.get);
訂閱:
文章 (Atom)