好!欢迎访问迷津渡口 现在时间是: 天气 °C ~ °C

迷津渡口

越感到迷惑 越接近真理

javascript的eval方法

在实际应用中,很多数据都存储在字符串里,通过转换后再处理数据非常繁琐,于是就有了eval方法。

语法:

eval(string)

用法:

参数是字符串,eval函数将计算字符串并执行其中的javascript代码。

注意参数必须是原始字符串而不是String对象,否则将返回错误,但接受字符串变量。

普通用例:

<script type="text/javascript">

eval("x=10;y=20;document.write(x*y)");

document.write(eval("2+2"));

var x=10
document.write(eval(x+17));

</script>

    输出结果:

200
4
27

检测异常:

try  {
     alert("Result:" + eval(prompt("Enter an expression:","")));
} catch(exception) {
    alert(exception);
}

特殊用例:

正则表达式包含变量

var x=document.getElementById("testX").nodeValue;
var y=document.getElementById("testY").nodeValue;
var reg=eval("/"+x+"/ig");
y.replace(reg,"testX");

转换json对象

var detailData=eval('('+request.responseText+')');

注意转换对象时需要添加括号,表示字符串需要转换为对象。


其他后面补充~

点赞0
   支持一下
挤眼 亲亲 咆哮 开心 想想 可怜 糗大了 委屈 哈哈 小声点 右哼哼 左哼哼 疑问 坏笑 赚钱啦 悲伤 耍酷 勾引 厉害 握手 耶 嘻嘻 害羞 鼓掌 馋嘴 抓狂 抱抱 围观 威武 给力
 点赞
 签到
 表情
 图片
 代码
提交评论

清空信息
关闭评论
esnafkocaeli
 esnafkocaeli 约 5 小时前回复
#129
<a href="http://www.colintilley.com/nike-kyrie-3-gelb-rosa-schuhei">nike kyrie 3 gelb rosa</a> <a href="http://www.xthbgc.com/nike-zoom-winflo-3-dam%C3%A4nner-orangen-blau-schuheh">nike zoom winflo 3 dam盲nner orangen blau</a> <a href="http://www.iberishop.com/nike-kd-9-gull-himmelen-bl%C3%A5-obuvj">nike kd 9 gull himmelen bl氓</a> <a href="http://www.karmacanix.com/nike-air-max-bw-nero-gituttio-scarpep">nike air max bw nero gituttio</a> <a href="http://www.tobepartridge.com/femmes-nike-free-tr-fit-jaune-vert-chaussuresh">femmes nike free tr fit jaune vert</a> <a href="http://www.shopdunks.com/prada-saffiano-metal-chain-wallet-pradah">prada saffiano metal chain wallet</a>
esnafkocaeli http://www.esnafkocaeli.com/
batatastudio
 batatastudio 约 15 小时前回复
#128
<a href="http://www.avantajreyonu.com/adidas-eqt-primeknit-nero-scarpej">adidas eqt primeknit nero</a> <a href="http://www.oranjeskishop.com/nike-high-tops-ic-indoor-magistax-proximo-rot-wei%C3%9F-schuhei">nike high tops ic indoor magistax proximo rot wei脽</a> <a href="http://www.johannafrost.com/nike-cortez-nylon-m%C3%A6nd-guld-gul-r%C3%B8d-skoh">nike cortez nylon m忙nd guld gul r酶d</a> <a href="http://www.rolandviet.com/russell-westbrook-hockey-jersey-nfli">russell westbrook hockey jersey</a> <a href="http://www.classmedya.com/nike-air-max-90-bl%C3%A5-svart-hvit-obuvk">nike air max 90 bl氓 svart hvit</a> <a href="http://www.anteageserums.com/coach-travel-luggage-set-coachh">coach travel luggage set</a>
batatastudio http://www.batatastudio.com/
timxes
 timxes 2019-03-18 18:30回复
#127
<a href="http://www.poppiesdelray.com/western-illinois-hat-hath">western illinois hat</a> <a href="http://www.soundsofbuzz.com/negro-rosado-blanco-nike-air-max-tn-mujer-zapatosl">negro rosado blanco nike air max tn mujer</a> <a href="http://www.hozloli.com/mens-nike-cortez-blue-gold-shoesk">mens nike cortez blue gold</a> <a href="http://www.privetaustria.com/le-coq-sportif-dark-gr%C3%B8nn-obuvi">le coq sportif dark gr酶nn</a> <a href="http://www.goodnnasty.com/mennns-nike-air-huarache-hvit-gr%C3%B8nn-obuvk">mennns nike air huarache hvit gr酶nn</a> <a href="http://www.ankarasanal.com/nike-roshe-run-mennns-r%C3%B8d-and-svart-obuvi">nike roshe run mennns r酶d and svart</a>
timxes http://www.timxes.com/
vspeyedoctors
 vspeyedoctors 2019-03-18 15:19回复
#126
<a href="http://www.onlyopenhomes.com/nike-kobe-9-mid-gelb-himmelblau-kurpesa">nike kobe 9 mid gelb himmelblau</a> <a href="http://www.ovnivape.com/nike-free-run-3-gris-mujeres-butyg">nike free run 3 gris mujeres</a> <a href="http://www.philipelara.com/addison-russell-jersey-cheap-nflx">addison russell jersey cheap</a> <a href="http://www.ehisem.com/nike-air-max-1-marina-militare-smoke-butyd">nike air max 1 marina militare smoke</a> <a href="http://www.mcharpi.com/curry-2-dam%C3%A4nner-tennis-schuhe-kurpesd">curry 2 dam盲nner tennis schuhe</a> <a href="http://www.naijafitgirl.com/ralph-lauren-hoodies-marinen-svart-polow">ralph lauren hoodies marinen svart</a>
vspeyedoctors http://www.vspeyedoctors.com/
raiedumacon
 raiedumacon 2019-03-18 10:55回复
#125
<a href="http://www.onlyopenhomes.com/nike-flyknit-roshe-run-lyser%C3%B8d-gr%C3%A5-obuvg">nike flyknit roshe run lyser酶d gr氓</a> <a href="http://www.ovnivape.com/nike-kyrie-3-jaune-quartz-scarpee">nike kyrie 3 jaune quartz</a> <a href="http://www.philipelara.com/nike-air-presto-rose-and-noir-butya">nike air presto rose and noir</a> <a href="http://www.ehisem.com/nike-lunarglide-8-binary-blau-key-chaussuresf">nike lunarglide 8 binary blau key</a> <a href="http://www.mcharpi.com/adidas-neo-cuero-marr%C3%B3n-amarillo-butya">adidas neo cuero marr贸n amarillo</a> <a href="http://www.naijafitgirl.com/adidas-superstar-sko-originals-schuheg">adidas superstar sko originals</a>
raiedumacon http://www.raiedumacon.com/
lmbaidu
 lmbaidu 2019-03-18 10:09回复
#124
<a href="http://www.domcilios.com/nike-air-force-1-puerto-rico-sko-shoesv">nike air force 1 puerto rico sko</a> <a href="http://www.zgzllc.com/coach-woven-hobo-tour-coachc">coach woven hobo tour</a> <a href="http://www.flibroactiv.com/bon-march%C3%A9-adidas-crazylight-boost-hommes-bleu-shoesc">bon march茅 adidas crazylight boost hommes bleu</a> <a href="http://www.tustinvillage.com/adidas-response-tr-boost-skos">adidas response tr boost</a> <a href="http://www.erickasouza.com/authentic-ferragamo-belt-beltr">authentic ferragamo belt</a> <a href="http://www.killersandbox.com/mackage-coat-sale-online-edition-mackagee">mackage coat sale online edition</a>
lmbaidu http://www.lmbaidu.com/
egyptmaritime
 egyptmaritime 2019-03-17 19:01回复
#123
<a href="http://www.cardiachits.com/nike-hypershift-argent-bleu-ciel-chaussuresl">nike hypershift argent bleu ciel</a> <a href="http://www.zestchannel.com/mujeres-asics-gel-lyte-5-verde-plata-zapatosq">mujeres asics gel lyte 5 verde plata</a> <a href="http://www.eczacinim.com/nike-zoom-winflo-3-kvinders-sort-lyser%C3%B8d-skoj">nike zoom winflo 3 kvinders sort lyser酶d</a> <a href="http://www.chilangorails.com/nike-air-max-95-r%C3%B8d-svart-obuvi">nike air max 95 r酶d svart</a> <a href="http://www.mariusen.com/adidas-springblade-solyce-blanco-oro-zapatosk">adidas springblade solyce blanco oro</a> <a href="http://www.brittonoilco.com/herre-nike-roshe-run-high-appelsin-bl%C3%A5-skoq">herre nike roshe run high appelsin bl氓</a>
[url=http://www.egyptmaritime.com/]egyptmaritime[/url]
philiphawley
 philiphawley 2019-03-17 09:28回复
#122
<a href="http://www.txmed.net/nike-flyknit-air-max-dame-for-salg-schuhed">nike flyknit air max dame for salg</a> <a href="http://www.ukpubs.net/herre-asics-gel-noosa-tri-8-hvid-r%C3%B8d-kurpesb">herre asics gel noosa tri 8 hvid r酶d</a> <a href="http://www.uniquewebsitedesign.net/nike-air-max-90-kpu-tpu-marr%C3%B3n-amarillo-kurpesa">nike air max 90 kpu tpu marr贸n amarillo</a> <a href="http://www.unratedperez.net/nike-free-5.0-femminile-glacier-ice-obuvb">nike free 5.0 femminile glacier ice</a> <a href="http://www.urbanintelligence.net/gr%C3%A5-and-lyser%C3%B8d-jordan-13-kurpesa">gr氓 and lyser酶d jordan 13</a> <a href="http://www.utsweb.net/nike-kobe-5-himmelbl%C3%A5-gul-butyd">nike kobe 5 himmelbl氓 gul</a>
philiphawley http://www.philiphawley.net/
amicsdelball
 amicsdelball 2019-03-17 08:37回复
#121
<a href="http://www.artenvironments.net/asics-gel-noosa-tri-10-l%C3%B8b-sko-schuhee">asics gel noosa tri 10 l酶b sko</a> <a href="http://www.ascential.net/nike-lunar-tempo-ii-blanc-vert-scarpee">nike lunar tempo ii blanc vert</a> <a href="http://www.associazioneagape.net/nike-air-max-90-sneakerboot-lilla-himmelen-bl%C3%A5-scarpeg">nike air max 90 sneakerboot lilla himmelen bl氓</a> <a href="http://www.atientertainment.net/adidas-nmd-runner-wei%C3%9F-tactile-gr%C3%BCn-eyes-kurpesa">adidas nmd runner wei脽 tactile gr眉n eyes</a> <a href="http://www.attawhed.net/air-max-thea-hvid-damskie-schuhee">air max thea hvid damskie</a> <a href="http://www.audichandler.net/nike-air-huarache-kinder-silber-wei%C3%9F-kurpesc">nike air huarache kinder silber wei脽</a>
amicsdelball http://www.amicsdelball.net/
viptarimas
 viptarimas 2019-03-17 07:15回复
#120
<a href="http://www.teamdalarna.com/femminile-air-max-90-em-nero-rosso-scarpel">femminile air max 90 em nero rosso</a> <a href="http://www.syairshamyoun.com/nike-air-max-infrared-velvet-shoesj">nike air max infrared velvet</a> <a href="http://www.fizalisfresh.com/michael-kors-bedford-belted-hobo-mkh">michael kors bedford belted hobo</a> <a href="http://www.fsscas.com/nike-sb-stefan-janoski-max-kvinners-s%C3%B8lv-oransje-obuvi">nike sb stefan janoski max kvinners s酶lv oransje</a> <a href="http://www.imagimp.com/maschio-nike-cortez-arancia-rosso-scarpej">maschio nike cortez arancia rosso</a> <a href="http://www.burmamaritime.com/womens-nike-air-max-95-green-grey-shoesh">womens nike air max 95 green grey</a>
viptarimas http://www.viptarimas.com/
顶部留言底部
 00:00/00:00
我想和你虚度时光 - 花房姑娘(9)
  1. 我想和你虚度时光
  2. 花房姑娘
  3. 恋恋风尘
  4. 我喜爱一切不彻底的事物
  5. 我的心里是满的
  6. Long Way
  7. 给少年的歌
  8. 晴日共剪窗
  9. 天上的月你的脸