执行javascript:链接+刷新。 JS + PHP

OK, so how can i make this link:

"javascript:elements.setPercentage('element1','".$value."')"

execute on my page, when the page is loaded?

you can either put it in the body tag like this:

<body onload="function(){elements.setPercentage('element1','".$value."')}"

or in your javascript file:

window.onload = function(){elements.setPercentage('element1','".$value."')};

Or in jQuery

$(document).ready(function(){elements.setPercentage('element1','".$value."')});

You need to wrap it in a function because you are sending arguments

If you're using native JS:

<body onload="/*whatever*/">...</body>

If you're using JQuery (better cross browser support for the following):

$(document).ready(function(){/*do whatever*/})

This example binds the window.onload event handler to an anonymous function. However, with this example, you can only have one handler (but as much code within it as you want).

jQuery, for example, has a more effective method called onDOMReady that you should consider.

<head>
... other stuff
<script>
window.onload = function(){
    if (typeof elements == 'object' and typeof elements.setPercentage == 'function') {
        elements.setPercentage('element1','<?php echo $value; ?>');
    }
}
</script>
... other stuff
</head>