怎么用js判断sql语句最后是否写分号

怎么用js判断sql语句最后是否写分号,第1张

资料:网页链接

javascript中判断字符串是否以指定字符串开始或结尾:

//判断当前字符串是否以str开始 先判断是否存在function是避免和js原生方法冲突,自定义方法的效率不如原生的高

if (typeof StringprototypestartsWith != 'function') {

   StringprototypestartsWith = function (str){         

      return thisslice(0, strlength) == str;

   };

}

//判断当前字符串是否以str结束

if (typeof StringprototypeendsWith != 'function') {

 StringprototypeendsWith = function (str){          

  return thisslice(-strlength) == str;

 };

}    

     

//测试程序

var sCompareStr = "select  from t1";//比较字符串

var sBeCompareStr = ";";//被比较字符串

if(sCompareStrendsWith(sBeCompareStr)){//这里可以替换为startsWith

    alert(sCompareStr+" 是以:"+sBeCompareStr+" 结束");

}else{

    alert(sCompareStr+" 不是以:"+sBeCompareStr+" 结束");

    sCompareStr +=sBeCompareStr ;//若无分号,将分号加到后面

}

这样书写的原因:

之所以在将整个代码放在if判断中是因为避免以后原生的js版本中增加了同类方法而导致代码效率降低。因为对于同名方法来说,js原生的代码效率要高于用户自己扩展的方法

之所以使用slice方法而不使用indexof方法,是由于indexof方法在处理较长的字符串时效率比较低

这个可以搬过去用,楼主若觉得回答有所帮助,望采纳,谢谢!

来凑个热闹。。

<script>var mtkxa = [];$(document)ready(function(){buildPage(mtkxa, "mtkxa", "width190");});</script>

<%

'把定义mtkxa,页面ready移动到最前面即可

set rs1=servercreateobject("ADODBRecordset")

sql1="select Top 5 ID,Title from Article where IsHot = 1 order by ID Desc"

rs1open sql1,conn,1,3

do while not rs1eof

%>

<h4><%=rs1("Title")%></h4>

<script>mtkxapush({title:'<%=rs1("Title")%>', url:'<%=apath(rs1("ID"),0)%>'});</script>

<%

rs1movenext

loop

rs1close

set rs1=nothing

%>

中间一个H4不知道干嘛的,输出这种数据建议直接用json,asp代码和html代码可以分开写

不论用什么语言做网站,json是迟早会接触到的。。很方便

建议写法:

<!--include file="jsonasp"-->

<%

'json处理类 到>

var xhao=Request("xuhao_flash");

var xming=Request("xingming_flash");

sql="select from shujubiao where xuhao like "+"'%"+xhao+"%' or xingming like '%"+xming+"%'";

以上就是关于怎么用js判断sql语句最后是否写分号全部的内容,包括:怎么用js判断sql语句最后是否写分号、javascript与SQL查询,循环执行、ASP中,用JS脚本写的SQL语句,调用 多个 变量 ,这样写为什么会出错应该如何写等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/9824634.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-02
下一篇 2023-05-02

发表评论

登录后才能评论

评论列表(0条)

保存