我想使用jquery比较一些文本,例如
var text = "ctl00_ContentPlaceHolder1_txtActivity";
var activityId = text.includes("txtActivity");
或
var activityId = (isd.indexOf("txtActivity") > -1);
上面的代码在crome和firefox中成功运行 但它在IE中出错 有没有其他方法来解决它 请帮忙
答案 0 :(得分:1)
使用模式匹配来执行此操作:
<div class="form-group">
<form>
<input type="text" ng-model="description" name="description" class="form-control" required>
<input type="text" ng-model="description" name="description" class="form-control" required>
<input type="text" ng-model="description" name="description" class="form-control" required>
<button type="submit">Save</button>
</form>
</div>
答案 1 :(得分:1)
indexOf
功能适用于所有浏览器。只需删除inculdes
路径,然后将变量名称更改为text
:
var text = "ctl00_ContentPlaceHolder1_txtActivity";
var activityId = text.indexOf("txtActivity") > -1;
console.log(activityId);
&#13;
答案 2 :(得分:0)
尝试此代码.. indexof工作所有浏览器..
<script>
var text = "ctl00_ContentPlaceHolder1_txtActivity";
var n = text.indexOf("txtActivityda");
if(n!== -1)
{
console.log("found")
}
else
{
console.log("not found")
}
</script>