这个jquery函数给我的宽度单击按钮时,但如何可以取代宽度页面加载时。我还需要在php文件中使用with变量。 这个b怎么做?调用jQuery的函数onload和var到php
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<button id="getp">Get Paragraph Width</button>
<button id="getd">Get Document Width</button>
<button id="getw">Get Window Width</button>
<div> </div>
<p>
Sample paragraph to test width
</p>
<script>
function showWidth(ele, w) {
$("div").text("The width for the " + ele + " is " + w + "px.");
}
$("#getp").click(function() {
showWidth("paragraph", $("p").width());
});
$("#getd").click(function() {
showWidth("document", $(document).width());
});
$("#getw").click(function() {
showWidth("window", $(window).width());
});
</script>
<?='this does not work '.$_GET['w'];?>
</body>
</html>
因为它在客户端和PHP在页面加载服务器端...该宽度你想 –
你的PHP你JavaSript之前甚至被处决执行,你不能在PHP中使用宽度可变到达用户的浏览器。 – George
看到http://jsfiddle.net/arunpjohny/nQkPt/2/ –