<script>
function isNumberPressed(){
var isValidKey = false;
var intCode = window.event.keyCode;
if (intCode >= 48 && intCode <= 57) isValidKey = true; //0-9
if (intCode == 13) isValidKey = true; //13 enter
if (intCode == 32) isValidKey = true; //32 spacebar
window.event.returnValue = isValidKey;
}
</script>
<input type=text name=txt1 id=txt1 onkeypress="javascript:isNumberPressed();">
2012年3月27日 星期二
javascript select new Option 用法
var myselect=document.getElementById("channels");
myselect.options[myselect.length] = new Option("123", "1", "", (channel==36)?1:0);
new Option("標題","value",沒用""即可,selected)
myselect.options[myselect.length] = new Option("123", "1", "", (channel==36)?1:0);
new Option("標題","value",沒用""即可,selected)
2012年3月25日 星期日
document.form1.xxx1-n多物件呼叫
for(var i=0;i<=10;i++)
{
var tmp=eval("document.form1.xxx"+i)
tmp.disabled=flase;
}
{
var tmp=eval("document.form1.xxx"+i)
tmp.disabled=flase;
}
2012年2月22日 星期三
Javascript控制iframe的url適用IE,google,FF
<script>
var iframe;
function set_status() {
iframe = document.getElementById("iframe");
iframe.onload = iframe.onreadystatechange = iframeload;
iframe.src = "http://tw.yahoo.com";
}
function iframeload() {
if (!iframe.readyState || iframe.readyState == "complete") {
alert("Local iframe is now loaded.");
}
}
</script>
<iframe id="iframe" name="iframe">
var iframe;
function set_status() {
iframe = document.getElementById("iframe");
iframe.onload = iframe.onreadystatechange = iframeload;
iframe.src = "http://tw.yahoo.com";
}
function iframeload() {
if (!iframe.readyState || iframe.readyState == "complete") {
alert("Local iframe is now loaded.");
}
}
</script>
<iframe id="iframe" name="iframe">
2011年12月21日 星期三
2011年12月18日 星期日
Javascript判斷瀏覽器語言
Chrome 8、Firefox 4、Opera 11 的 window.navigator.language 可以获取语言,
而 ie6、7、8 、9的 window.navigator 有 userLanguage 和 systemLanguage 两个属性,
并且 ie9 还多了个 browserLanguage 属性。
一般来说 window.navigator.userLanguage || window.navigator.language 应该能应付得了。
而 ie6、7、8 、9的 window.navigator 有 userLanguage 和 systemLanguage 两个属性,
并且 ie9 还多了个 browserLanguage 属性。
一般来说 window.navigator.userLanguage || window.navigator.language 应该能应付得了。
Javascript判斷用哪一種瀏覽器
<script>
var isIE = navigator.userAgent.search("MSIE") > -1;
var isIE7 = navigator.userAgent.search("MSIE 7") > -1;
var isFirefox = navigator.userAgent.search("Firefox") > -1;
var isOpera = navigator.userAgent.search("Opera") > -1;
var isSafari = navigator.userAgent.search("Safari") > -1;//Google瀏覽器是用這核心
if (isIE7) {
alert('isIE7');
}
if (isIE) {
alert('isIE');
}
if (isFirefox) {
alert('isFirefox');
}
if (isOpera) {
alert('isOpera');
}
if (isSafari) {
alert('isSafari');
}
</script>
var isIE = navigator.userAgent.search("MSIE") > -1;
var isIE7 = navigator.userAgent.search("MSIE 7") > -1;
var isFirefox = navigator.userAgent.search("Firefox") > -1;
var isOpera = navigator.userAgent.search("Opera") > -1;
var isSafari = navigator.userAgent.search("Safari") > -1;//Google瀏覽器是用這核心
if (isIE7) {
alert('isIE7');
}
if (isIE) {
alert('isIE');
}
if (isFirefox) {
alert('isFirefox');
}
if (isOpera) {
alert('isOpera');
}
if (isSafari) {
alert('isSafari');
}
</script>
訂閱:
文章 (Atom)