<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<script>
window.onload = function () {
var id = '1';
var code = 'zhangsan';
var name = '张三';
document.getElementById('test').innerHTML = '<a href="#" onclick="buttonClick(\"' + id + '\",\"' + code + '\">' + name + '</a>';
}
function buttonClick(id, code) {
alert(id + '-' + code);
}
</script>
</head>
<body>
<div id="test"></div>
</body>
</html>
(function () {
/// <summary>
/// 引号转义符号
/// </summary>
String.EscapeChar = '\'';
/// <summary>
/// 替换所有字符串
/// </summary>
/// <param name="searchValue">检索值</param>
/// <param name="replaceValue">替换值</param>
String.prototype.replaceAll = function (searchValue, replaceValue) {
var regExp = new RegExp(searchValue, "g");
return this.replace(regExp, replaceValue);
}
/// <summary>
/// 格式化字符串
/// </summary>
String.prototype.format = function () {
var regexp = /\{(\d+)\}/g;
var args = arguments;
var result = this.replace(regexp, function (m, i, o, n) {
return args[i];
});
return result.replaceAll('%', String.EscapeChar);
}
})();
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<script src="String.js"></script>
<script>
window.onload = function () {
var id = '1';
var code = 'zhangsan';
var name = '张三';
document.getElementById('test').innerHTML = '<a href="#" onclick="buttonClick(%{0}%,%{1}%)">{2}</a>'.format(id, code, name);
}
function buttonClick(id, code) {
alert(id + '-' + code);
}
</script>
</head>
<body>
<div id="test"></div>
</body>
</html>
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有