Ale*_*Mcp 13 javascript jquery
在Ruby中你可以像这样使用字符串插值:
text = "This is visit number #{numVisits} to this website"
Run Code Online (Sandbox Code Playgroud)
这绕过了显式连接的需要.
我正在使用jQuery并且有点像这样:
$(document).ready(function(){
$("a.ajax").click(function(event){
$("#content").load("data.html this.getClass");
});
});
Run Code Online (Sandbox Code Playgroud)
我想要的行为是"点击<a class="ajax" id="schedule"></a>并content div在当前页面上替换为schedule divfrom data.html.如果我手动写入
load("data.html #test");
Run Code Online (Sandbox Code Playgroud)
这工作,但我希望脚本加载DIV与点击锚点的ID值.任何帮助都会膨胀!
Mar*_*cos 17
这已经改变了.
截至2015年,现在有一种更好的方法:https: //developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/template_strings
为JS带来了许多像Ruby和PHP这样的语言已经享受过的东西.
例如,在我的jQuery驱动页面中,我使用:
$('#myModalLabel').html(`Show GRAPH of : ${fundCode}-${funcCode}`);
Run Code Online (Sandbox Code Playgroud)
在我更新的Firefox和Chrome中安全地呈现为:
显示GRAPH:AIP001-_sma
注意在.html(....)中使用围绕字符串参数的反引号
在 es6 中这是可能的
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/template_strings
`string text ${expression} string text`
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
12499 次 |
| 最近记录: |