js traversal pass parameters to 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 () method returns or sets the contents of the selected element (inner HTML). If the method parameter is not set, the contents of the currently selected element is returned. 
var buttonHtml = $ ( "# SUBP" ) .html ();
 // Split () method for dividing a character string into a string array, there are several view Button 
var buttoum = (buttonHtml.split ( '<Button' .)). 1-length ;
 for ( var m = 0; m <buttoum; m ++ ) {
     // iterate the number of buttons, string @params_ pickup position, to be replaced, until no, the indexOf () returns a position specified string value in the first occurrence of the string 
    var startm = buttonHtml.indexOf ( '@ params_' );
     // do not exist, the following operation is not required 
    IF (startm> = 0 ) {
         var ENDM = buttonHtml .indexOf ( '@ \') ' );
        
        var iteme = buttonHtml.substring (startm, ENDM +. 1 );
         // string @ params_id @ Alternatively, Replace () method is used to replace some other character string some characters are used, or alternatively a regular expression match substring 
        buttonHtml = buttonHtml.replace (iteme, "" + menuList.subModuleList [K] .id + "" ) 
    } the else {
         BREAK ; 
    } 
} 
HTML + = buttonHtml;

Main methods:
split () divided array of strings
indexOf () returns the position of the mark for the first time
substring () extracts a character between two specified index
replace () character replacement

Guess you like

Origin www.cnblogs.com/hpwd/p/11118763.html