js匹配变量中的某个字符串
答案:1 悬赏:10 手机版
解决时间 2021-02-11 18:36
- 提问者网友:几叶到寒
- 2021-02-11 03:31
$.each(e, function(i,value) { <br> var myobj=eval(value); <br> var str="";<br> for(var i=0;i<myobj.length;i++){ <br> name=myobj[i].name;<br> idPath=myobj[i].idPath;<br> alert(idPath);<br> // str+="<option value="+id+">"+name+"</option>";<br> //t.innerHTML = "<option value="+id+">"+name+"</option>";<br> } <br> $('#diz').append(str); <br> });<br> idPath格式:\1<br>或者\1\2<br>或\1\2\3<br>就这三种格式 我想把\1的输出怎么做
最佳答案
- 五星知识达人网友:天凉才是好个秋
- 2021-02-11 03:59
<!DOCTYPE HTML>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<title>menu</title>
<style type="text/css">
</style>
<script type="text/javascript" src="jquery-1.8.0.min.js"></script>
<script type="text/javascript">
$ (function ()
{
var e = [
[
{
name : 11,
idPath : "\\1"
},
{
name : 22,
idPath : "\\1\\2"
}
], [
{
name : 33,
idPath : "\\1"
},
{
name : 44,
idPath : "\\1\\2\\3"
}
]
];
var diz = $ ('#diz');
$.each (e, function (i, value)
{
var str = "";
$ (value).each (function (j, dom)
{
name = dom.name;
idPath = dom.idPath;
if (/^\\[^\\]+$/.test (idPath))
{
str += "<option value="+idPath+">" + name + "</option>";
}
});
diz.append (str);
});
})
</script>
</head>
<body>
<select id="diz"></select>
</body>
</html>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<title>menu</title>
<style type="text/css">
</style>
<script type="text/javascript" src="jquery-1.8.0.min.js"></script>
<script type="text/javascript">
$ (function ()
{
var e = [
[
{
name : 11,
idPath : "\\1"
},
{
name : 22,
idPath : "\\1\\2"
}
], [
{
name : 33,
idPath : "\\1"
},
{
name : 44,
idPath : "\\1\\2\\3"
}
]
];
var diz = $ ('#diz');
$.each (e, function (i, value)
{
var str = "";
$ (value).each (function (j, dom)
{
name = dom.name;
idPath = dom.idPath;
if (/^\\[^\\]+$/.test (idPath))
{
str += "<option value="+idPath+">" + name + "</option>";
}
});
diz.append (str);
});
})
</script>
</head>
<body>
<select id="diz"></select>
</body>
</html>
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯