js遍历传参到html
<p id="subp" hidden><button id= "upsub"shiro:hasPermission="sys:menu:edit" type="button" class="btn btn-success" onclick="updateById('@params_id@')">
<i aria-hidden="true"></i>修改
</button>
<button id= "delsub" shiro:hasPermission="sys:menu:del" type="button" class="btn btn-danger" onclick="delById('@params_id@')">
<i aria-hidden="true"></i>删除 </button>
<button id= "findsub" shiro:hasPermission="sys:menu:view" type="button" class="btn btn-info" onclick="findById('@params_id@')">
<i aria-hidden="true"></i>查看
</button>
</p>
JS:
//html() 方法返回或设置被选元素的内容 (inner HTML)。如果该方法未设置参数,则返回被选元素的当前内容。
var buttonHtml = $("#subp").html();
//split() 方法用于把一个字符串分割成字符串数组,查看有几个button
var buttoum = (buttonHtml.split('<button')).length-1;
for(var m=0;m<buttoum;m++){
//遍历按钮个数,取出@params_字符串的位置,进行替换,直至没有为止,indexOf()可返回某个指定的字符串值在字符串中首次出现的位置
var startm = buttonHtml.indexOf('@params_');
//不存在,则不需要进行下面操作
if(startm>=0){
var endm = buttonHtml.indexOf('@\')');
//substring() 方法用于提取字符串中介于两个指定下标之间的字符
var iteme = buttonHtml.substring(startm,endm+1);
//将字符串@params_id@替换,replace() 方法用于在字符串中用一些字符替换另一些字符,或替换一个与正则表达式匹配的子串
buttonHtml = buttonHtml.replace(iteme,""+menuList.subModuleList[k].id+"")
}else{
break;
}
}
html += buttonHtml;
主要方法:
split()分割字符串数组
indexOf()返回标志首次出现的位置
substring()提取两个指定下标之间的字符
replace()字符替换
js遍历传参到html的更多相关文章
- js遍历传参给html
<p id="subp" hidden><button id= "upsub"shiro:hasPermission="sys:me ...
- EL表达式的js函数传参问题
<!Doctype html> <html> <head> <title>js的传参问题</title> <script type=& ...
- js url传参,参数加密
前台 function encode64(input) { var output = ""; var base = new Base64(); var output = base. ...
- js构造函数传参
1.直接传参并用this关键字初始化属性 function Person(name,age,learn){ this.name = name; this.age = age; this.learn = ...
- js get 传参 汉字 乱码问题
js encodeURI(encodeURI(searchWord)) java URLDecoder.decode(searchWord,"utf-8")
- 用js来传参到父网页实现
今天搞了半天,用location.href提交参数到后台,结果php无法接收到参数,这让我找了半天,终于发现原因是本页被另外的主页引用了,最终发现问题出在提交js上,最终用parent.locatio ...
- js SetTimeout传参问题
今天写代码遇到这样一个问题,先上代码 <!--JS方法--> function textout(obj){ if(opac==60){opac=0;return;}; opac+=10; ...
- JS 内部传参
- tp5中url使用js变量传参方法
window.location.href="{:url('Index/index')}>"+"/ID/"+ID; //这样可以生成,但url模式改变则不能 ...
随机推荐
- centos docker 防火墙设置(多个ip之间互相访问)
[Solution] Update firewall policy 1) Disabled docker rules of iptables --- docker will create ...
- 【PAT甲级】1116 Come on! Let's C (20分)
题意: 输入一个正整数N(<=10000),接着依次输入N个学生的ID.输入一个正整数Q,接着询问Q次,每次输入一个学生的ID,如果这个学生的ID不出现在之前的排行榜上输出Are you kid ...
- style.display = "inline或inline";和style.display = "";的区别
function a(){ if($('#b').attr('checked')){ $('.c').css("display",""); //"di ...
- Wannafly Camp 2020 Day 3C 无向图定向
请你把无向图的每条边确定一个方向,使之成为一个DAG,并且最小化最长路的长度. #include <bits/stdc++.h> using namespace std; int n,m, ...
- jmeter下载安装---已有jmeter脚本使用方法
一.jmeter下载安装 1.下载地址:http://jmeter.apache.org/download_jmeter.cgi 下载下来为一个压缩包,解压即可 解压后目录结构如下: 2.jmeter ...
- LoadRunner使用记录
基本术语 性能测试--通过自动化的测试工具模拟多种正常.峰值以及异常负载条件来对系统的各项性能指标进行测试. 负载测试和压力测试都属于性能测试,两者可以结合进行. 负载测试,确定在各种工作负载下系统的 ...
- 优酷1080p的kux格式文件转码
@echo off for /r . %%i in (*.kux) do ( "C:\Program Files (x86)\YouKu\YoukuClient\nplayer\ffmpeg ...
- php核心技术与最佳实践 --- 错误与异常
<?php /*php error*/ /* * 异常和错误的概念不一样 * 在PHP里,遇到任何自身错误都会触发一个错误,而不是抛出异常(对于一些情况,会同时抛出异常和错误) * 异常处理机制 ...
- java8快速实现分组、过滤、list转map
public class TestEntity { private String c1; private String c2; public TestEntity(){} public TestEnt ...
- 安装node.js后npm不可用
安装node.js后npm不可用 最近要用Vue做项目,依赖node.js,于是按官网下载安装node 下载地址:https://nodejs.org/en/download/ 网上也有很多教程这里就 ...