开发者

change the style of menu, if it is selected, without php

开发者 https://www.devze.com 2022-12-25 16:58 出处:网络
how can i change the style of menu, if it is selected, without php? i can do it by php `<? if($_GET[id] == \"this_menu\") echo \"style=\'color开发者_开发问答:red\'\"?>`

how can i change the style of menu, if it is selected, without php? i can do it by php

`<? if($_GET[id] == "this_menu") echo "style='color开发者_开发问答:red'"?>` 

but i want to do it without php. is it possible? thanks


if (document.location.search.match(/[?&]id=this_menu([&.*])?$/)) {
    document.getElementById('yourId').setAttribute('style', 'color: red');
}


Do you want to do that on client? if so, use JavaScript.


With JS

document.getElementById(gup("param")).setAttribute('style', 'color: red');

function gup( param ) {

var name = param.toLowerCase();
var regexS = "[\?&]"+name+"=([^&#]*)";
var regex = new RegExp( regexS ); var tmpURL = window.location.href;
var results = egex.exec( tmpURL );
if( results == null ) { // Try to find an alternative value
if (typeof alternatives == "object") {
if(typeof alternatives[name] !="undefined") { return alternatives[name];
}
} return "";
} else {
return results[1];
} };


it can be done easily done by javascript:

use something like this

document.getElementById('myMenu').style.color='#f0f0f0';

0

精彩评论

暂无评论...
验证码 换一张
取 消