求一段JS代码,要求搜索当前页面,如果发现当前页面中有设定的字...
<script>function searchWords() {var words = document.getElementById('search').value;if (words != '') {var innerHTML = document.body.innerHTML;if (innerHTML.indexOf(words) != -1) {alert('找到了');if (words == '123') {alert('123不作操作');} else if (words == '456') {alert('456跳转页面');window.location.href = 'http://www.baidu.com';} else if (words == '567') {alert('567替换内容');document.body.innerHTML = innerHTML.replace(new RegExp(/(567)/g),'789');}}}}</script>123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ查询
用JS怎样获取文本框的值
展开全部 document.forms.0.thistext.valueTable of Contents | Previous | Next | IndexTextA text input field on an HTML form. The user can enter a word, phrase, or series of numbers in a text field.Client-side objectImplemented inJavaScript 1.0JavaScript 1.1: added type propertyJavaScript 1.2: added handleEvent methodCreated byThe HTML INPUT tag, with "text" as the value of the TYPE attribute. For a given form, the JavaScript runtime engine creates appropriate Text objects and puts these objects in the elements array of the corresponding Form object. You access a Text object by indexing this array. You can index the array either by number or, if supplied, by using the value of the NAME attribute.To define a Text object, use standard HTML syntax with the addition of JavaScript event handlers.Event handlers * onBlur * onChange * onFocus * onSelect DescriptionA Text object on a form looks as follows:A Text object is a form element and must be defined within a FORM tag.Text objects can be updated (redrawn) dynamically by setting the value property (this.value).Property SummaryProperty DescriptiondefaultValueReflects the VALUE attribute.formSpecifies the form containing the Text object.nameReflects the NAME attribute.typeReflects the TYPE attribute.valueReflects the current value of the Text object's field.Method SummaryMethod DescriptionblurRemoves focus from the object.focusGives focus to the object.handleEventInvokes the handler for the specified event.selectSelects the input area of the object.In addition, this object inherits the watch and unwatch methods from Object.ExamplesExample 1. The following example creates a Text object that is 25 characters long. The text field appears immediately to the right of the words "Last name:". The text field is blank when the form loads.Last name: Example 2. The following example creates two Text objects on a form. Each object has a default value. The city object has an onFocus event handler that selects all the text in the field when the user tabs to that field. The state object has an onChange event handler that forces the value to uppercase.City: State: See also the examples for the onBlur, onChange, onFocus, and onSelect.See alsoText, Form, Password, String, TextareablurRemoves focus from the text field.Method ofTextImplemented inJavaScript 1.0Syntaxblur()ParametersNoneExamplesThe following example removes focus from the text element userText:userText.blur()This example assumes that the text element is defined asSee alsoText.focus, Text.selectdefaultValueA string indicating the default value of a Text object.Property ofTextImplemented inJavaScript 1.0SecurityJavaScript 1.1. This property is tainted by default. For information on data tainting, see the Client-Side JavaScript Guide.DescriptionThe initial value of defaultValue reflects the value of the VALUE attribute. Setting defaultValue programmatically overrides the initial setting.You can set the defaultValue property at any time. The display of the related object does not update when you set the defaultValue property, only when you set the value property.ExamplesThe following function evaluates the defaultValue property of objects on the surfCity form and displays the values in the msgWindow window:function defaultGetter() { msgWindow=window.open("") msgWindow.document.write("hidden.defaultValue is " + document.surfCity.hiddenObj.defaultValue + "") msgWindow.document.write("password.defaultValue is " + document.surfCity.passwordObj.defaultValue + "") msgWindow.document.write("text.defaultValue is " + document.surfCity.textObj.defaultValue + "") msgWindow.document.write("textarea.defaultValue is " + document.surfCity.textareaObj.defaultValue + "") msgWindow.document.close()}See alsoText.valuefocusNavigates to the text field and gives it focus.Method ofTextImplemented inJavaScript 1.0Syntaxfocus()ParametersNoneDescriptionUse the focus method to navigate to a text field and give it focus. You can then either programmatically enter a value in the field or let the user enter a value. If you use this method without the select method, the cursor is positioned at the begin...
js改变数组顺序
function arr(){var inPut = document.ElementById("获取输入的值").value;var index = inPut.split("");var Arr = ["10","9","8","7"];for(var i =0; iArr[i] = Arr[parseInt(index[i])];}return Arr;}
JS、AJAX等实现:HTML/JSP页面中即时显示查询的数据,怎么写?
展开全部 struts2 action 代码import java.io.IOException;import java.io.PrintWriter;public class AutoComplete extends CommonAction { /** * 用于实践ajax google 的样式 * 用于接收服务器端请求的 */ //抓取从页面穿过来的字符串 用于和服务器端的单词进行匹配 private String word ; public AutoComplete() { } public String onblurquery() throws Exception{ //保存要查询的东西 //注意ajax 中 这个所谓的视图层不返回页面 只返回数据 this.getRequestMap().put("word", word); //System.out.println("struts - > "+word); this.getResponse().setContentType("text/xml;charset=utf-8;"); return "toshow"; } public String getWord() { return word; } public void setWord(String word) { this.word = word; }}jsp 代码 google /*当文本没有被选中的时候就使用这个样式*/ .auto-1{ background-color: #FFCC99; color: gray; cursor: pointer; width: 100%; } /*当文本被选中的时候就是用这个样式*/ .auto-2{ background-color: #CCFF99; color: green; cursor: pointer; width: 100%; } google: jquery 代码 //表示当前被选中的节点 var highlightindex = -1; var timeoutId; $(document).ready(function (){ //alert("准备好了"); //保存文本输入框 var wordinput=$("#word"); //保存文本的 var wordinputOffset = wordinput.offset(); //弹出框应该等于在文本的下面 那么就是文本的宽等于div的宽 $("#auto").hide().css("border","1px solid #CDD2CB").css("position","absolute") .css("top",wordinputOffset.top+wordinput.height()+5+"px").css("left",wordinputOffset.left+"px").width(wordinput.width()+40+"px"); //给文本框添加键盘按下并谈起的实践 $("#word").keyup(function (event){ //处理键盘实践 var myEvent = event || window.event; //如果输入的是字母 应该是将文本中最新的信息发送到服务器 //如果是退格或是删除键 那么就将文本中最新的信息发送给服务器 var keyCode = myEvent.keyCode; if(keyCode >= 65 && keyCode ").attr("id",i); newdivNode.addClass("auto-1").html(wordN.text()).appendTo(autoNode); //给鼠标加入进入的时候就高亮 newdivNode.mouseover(function (){ if(highlightindex!=-1){ $("#auto").children("div").eq(highlightindex).removeClass("auto-2").addClass("auto-1"); } highlightindex = $(this).attr("id"); $(this).removeClass("auto-1").addClass("auto-2"); }); //鼠标移出的加上的样式 newdivNode.mouseout(function (){ $(this).removeClass("auto-2").addClass("auto-1"); }); //鼠标点击的时候增加的样式 newdivNode.click(function (){ //取出文本的内容 var comtext = $(this).text(); $("#auto").hide(); //隐藏的时候就把节点重新的赋值 highlightindex = -1; $("#word").val(comtext); }); }); if(wordNode.length>0){ if($("#word").val()==""){ $("#auto").hide(); //隐藏的时候就把节点重新的赋值 highlightindex = -1; }else{ $("#auto").show(); } }else{ $("#auto").hide(); //隐藏的时候就把节点重新的赋值 highlightindex = -1; } //alert(data); },"xml"); },500); }else{ $("#auto").hide(); //隐藏的时候就把节点重新的赋值 highlightindex = -1; } }else if(keyCode == 38 || keyCode == 40){ //如果是按得向上或是向下键 if(keyCode == 38){ //上 var autoNodes = $("#auto").children("div"); if(highlightindex!=-1){ autoNodes.eq(highlightindex).removeClass("auto-2").addClass("auto-1"); highlightin...
jquery或js读取xml文件
参考代码如下: jQuery 读取XML文件-jQueryh1{color:Green;text-align:center;}body{ background-color:#EEEEEE ; font-family:微软雅黑; }#showresult{width:600px;overflow:hidden;}</script> $(document).ready(function () {$("#read").click(function () {$.ajax({//请求方式为gettype: "GET",//xml文件位置url: "sitemap.xml",//返回数据格式为xmldataType: "xml",//请求成功完成后要执行的方法success: function (xml) {$(xml).find("url").each(function (i) {//i从0开始,累加,如果要显示所有数据,将判断去除即可if (i //链接地址var location = $(this).find("loc").text();//显示文字var text = $(this).find("loc").text();//动态加载方法:链接地址$("").attr("href", location)//显示文字.text(text)//设置样式.css({ "width": "700px", "float": "left", "margin-bottom": "5px" })//加载到div.appendTo("#showresult");}})}});return false;});});</script>
javascript package是关键字吗
不是关键字Javascript关键字(Reserved Words)是指在Javascript语言中有特定含义,成为Javascript语法中一部分的那些字。
Javascript关键字是不能作为变量名和函数名使用的。
使用Javascript关键字作为变量名或函数名,会使Javascript在载入过程中出现编译错误。
Javascript关键字列表: break delete function return typeof case do if switch var catch else in this void continue false instanceof throw while debugger finally new true with default for null try Javascript未来关键字(Javascript Future Reserved Words) Javascript还有一些未来关键字,这些字虽然现在没有用到Javascript语言中,但是将来有可能用到。
Javascript未来关键字列表: abstract double goto native static boolean enum implements package super byte export import private synchronized char extends int protected throws class final interface public transient const float long short volatile
js 大括号含义
定义和用法split() 方法用于把一个字符串分割成字符串数组。
语法stringObject.split(separator,howmany)参数描述separator 必需。
字符串或正则表达式,从该参数指定的地方分割 stringObject。
howmany 可选。
该参数可指定返回的数组的最大长度。
如果设置了该参数,返回的子串不会多于这个参数指定的数组。
如果没有设置该参数,整个字符串都会被分割,不考虑它的长度。
返回值一个字符串数组。
该数组是通过在 separator 指定的边界处将字符串 stringObject 分割成子串创建的。
返回的数组中的字串不包括separator 自身。
但是,如果 separator 是包含子表达式的正则表达式,那么返回的数组中包括与这些子表达式匹配的字串(但不包括与整个正则表达式匹配的文本)。
提示和注释注释:如果把空字符串 ("") 用作 separator,那么 stringObject 中的每个字符之间都会被分割。
注释:String.split() 执行的操作与 Array.join 执行的操作是相反的。
实例例子 1在本例中,我们将按照不同的方式来分割字符串:var str="How are you doing today?"document.write(str.split(" ") + "")document.write(str.split("") + "")document.write(str.split(" ",3))<&#47;script>输出:How,are,you,doing,today?H,o,w, ,a,r,e, ,y,o,u, ,d,o,i,n,g, ,t,o,d,a,y,?How,are,you例子 2在本例中,我们将分割结构更为复杂的字符串:"2:3:4:5".split(":") //将返回["2", "3", "4", "5"]"|a|b|c".split("|") //将返回["", "a", "b", "c"]例子 3使用下面的代码,可以把句子分割成单词:var words = sentence.split(' ');或者使用正则表达式作为 separator:var words = sentence.split(/\s+/);例子 4如果您希望把单词分割为字母,或者把字符串分割为字符,可使用下面的代码:"hello".split("") //可返回 ["h", "e", "l", "l", "o"]若只需要返回一部分字符,请使用 howmany 参数:"hello".split("", 3) //可返回 ["h", "e", "l"]
jsonp 是什么?jsonp如何实现js跨域
测试页面var timeChin = ["零", "一", "二", "三", "四", "五", "六", "七", "八", "九", "十"];var urodz= new Date("3/1/2010 00:00");// 建坛时间function toWords(num){var str = "" + num;var buttomNum = 1;for(var i=0; ibuttomNum *= 10;}var retStr = "";var numCopy = num;for(var i=0; iretStr += timeChin[((numCopy/buttomNum)>>0)];numCopy = numCopy%buttomNum;buttomNum = buttomNum/10;}return retStr;}function showHistory(){var nowDay = new Date();var year = nowDay.getYear()-urodz.getYear();var month = nowDay.getMonth()-urodz.getMonth();var ddate = nowDay.getDate()-urodz.getDate();if(monthif(year==0)if(ddate>0||ddatemonth++;if(month==12){year++;month=0;}var str = toWords(year) + "年" + toWords(month) + "月";document.getElementById("_lefttime").innerHTML = str;}//--></script>现在是看一下吧。
要是觉得不合适,可以自己修改一下。
里面的功能都不难,慢慢看,能看懂的。
(numCopy/buttomNum)>>0 这个是用来取整的。
。
。
别的应该没有什么难度了。