js常用操作
2010-01-18 14:31
225 查看
1.禁用按钮和判断text值是否发生改变
js代码如下:
HTML部分
2.js动态更换图片
js代码如下:
其中return false;一定要加不然ie6不会更改图片,具体什么原因不清楚。。。
3.去除字符串中的空格:
js代码如下:
var changing; function changeBegin() { changing = setInterval("onChange()",100); } function onChange() { if(document.getElementById("Text1").value != document.getElementById("Text2").value) { document.getElementById("onOk").disabled = true; } else { document.getElementById("onOk").disabled = false; } } function changeEnd() { clearInterval(changing); }
HTML部分
<input id="Text1" type="text" name="textfield" runat="server"> <input id="Text2" type="text" name="textfield2" runat="server" onfocus="javascript:changeBegin()" onblur ="javascript:changeEnd()"> <INPUT type="button" id="onOk" value="Button">
2.js动态更换图片
js代码如下:
var changing; function changeBegin() { changing = setInterval("onChange()",100); } function onChange() { if(document.getElementById("Text1").value != document.getElementById("Text2").value) { document.getElementById("IMG1").src = "images/8_26.jpg"; return false; } else { document.getElementById("IMG1").src = "images/会员1_08.jpg"; return false; } } function changeEnd() { clearInterval(changing); }
其中return false;一定要加不然ie6不会更改图片,具体什么原因不清楚。。。
3.去除字符串中的空格:
var str = " hello "; var test = str.replace(/(^/s*)|(/s*$/g,"");//去除两边空格 //test = str.replace(/(^/s*)/g,""); //去除左边空格 //test = str.replace(/(/s*$)/g,""); //去除右边空格 alert("#"+test+"#");
相关文章推荐
- js常用操作函数
- javascript中字符串常用操作总结、JS字符串操作大全
- js数组常用操作方法汇总——entries
- JS中常用操作技巧(页面动态增加div,contain方法扩展,JSON对象鱼字符串转换)
- 关于下拉框的常用js操作
- js String对象中常用方法小结(字符串操作)
- JS操作HTML节点常用到的方法和节点属性
- js 常用操作保留
- JS 操作IE游览器常用函数:window.external,history,document.execCommand,window.location,WebBrowser.ExecWB
- JS中操作数组的常用函数
- 认识JQuery,JQuery的优势、语法、多库冲突、JS原生对象和JQuery对象之间相互转换和DOM操作,常用的方法
- js 日期常用操作
- JS 常用字符串操作
- node.js文件及文件夹常用操作
- 项目中常用的JS操作技巧
- Js操作Excel常用方法
- js一些常用操作