js输出字符串

var s="你要输出的字符串";document.write(s);

可以用indexof方法 往indexof传入一个值会返回该值在字符串中或者数组中的下标,返回-1即找不到该值 下面一个例子:<script> var str = "asdtestasd", arr = ["a","s","asd","asdf","test"]; console.log(str.indexof('test'));//输出3,下标为3 console.log(str.indexof('text'));//输出-1,找不到 console.log(arr.indexof('test'));//输出4,数组也是可以的</script>

1. 用innerhtml这个函数2. 用write这个函数输出到页面3. 现在谷歌浏览器还可以用console4. jquery用$().text()

<script type="text/javascript"> function change() { var str1 = document.getElementById("str1").value; var str2 = ""; for (var i = 0; i < str1.length; i++) { str2 += str1.charAt(str1.length - i) + "#"; } document.getElementById("str2").value = (str2

var text = &quot; yao a day yao without rain yao &quot;;<br>var myName = &quot;yao&quot;<br>if(text.indexOf(myName) != -1){<br> alert(&quot;yes&quot;);<br><br>}else{<br> alert(&quot; no&quot;);<br><br>}

先获取到指定的html元素,jquery的实现方法是$("#id").html("xxxxx")

<script> document.write("<table>"); for(i=1;i<11;i++) { document.write("<tr><td align=center>"); var str=""; for(j=1;j<=i;j++) { str=str+"*"; } document.write(str); document.write("</td></tr>") } document.write("</table>");</script>

<script> document.write(""); for(i=1;i{ document.write(""); var str=""; for(j=1;j { str=str+"*"; } document.write(str); document.write("") } document.write("");</script>

在action里指定response对象参数即可,不需要再服务器生成文件,直接字符串写入流 response.setContentType("application/x-msdownload"); response.setHeader("Content-Disposition","attachment;" + " filename="+pid+".html"); response.getOutputStream().write(text.getBytes()); response.getOutputStream().flush(); }

var text = " yao a day yao without rain yao ";var myName = "yao"if(text.indexOf(myName) != -1){ alert("yes");}else{ alert(" no");}

相关文档

javascript字符串
字符串索引js
js字符串compare
js截取字符串
js字符串操作方法
js字符串原样输出
js正则表达式
js字符串中间添加字符
wwgt.net
qhnw.net
ldyk.net
sytn.net
qwrx.net
电脑版