replace_html_tag_attr:
function
(src_str, tag, attr, val) {
if
(
typeof
src_str ===
'undefined'
||
typeof
tag ===
'undefined'
||
typeof
attr ===
'undefined'
||
typeof
val ===
'undefined'
) {
return
''
;
}
var
reg =
new
RegExp(
'<'
+ tag +
'[^>]*('
+ attr +
'=[\'\"](\\w*%?)[\'\"])?[^>]*>'
,
'gi'
);
return
src_str.replace(reg,
function
(match) {
if
(match.indexOf(attr) > 0) {
var
sub_reg =
new
RegExp(attr +
'=[\'\"](\\w*%?)[\'\"]'
,
'gi'
);
return
match.replace(sub_reg, attr +
'='
+ val);
}
else
{
return
match.substr(0, tag.length + 1) +
' '
+ attr +
'='
+ val +
' '
+ match.substr(tag.length + 2, match.length);
}
});
}