嘗試是這樣的:
<div id="mydiv">
<span id="username">Alex</span> click on this div
</div>
<script>
$('#mydiv').click(function(){
window.open(' /chatwindow/?user='+$('#username').text(), '_blank', 'width=300,height=400');
return false;
});
</script>
或者這
<div id="mydiv">
Alex click on this div
</div>
<script>
var username = 'Alex';
$('#mydiv').click(function(){
window.open(' /chatwindow/?user='+username, '_blank', 'width=300,height=400');
return false;
});
</script>
或者這
<div id="mydiv">
Alex click on this div
<input type="hidden" name="username" value="Alex">
</div>
<script>
var username = 'Alex';
$('#mydiv').click(function(){
window.open(' /chatwindow/?user='+$('#mydiv > input[name="username"]').val(), '_blank', 'width=300,height=400');
return false;
});
</script>
好THX!這幾乎是它,但1 JS腳本已促進多個div,所以一種方式來傳遞用戶名從像id =「alex」的元素,並使用它,然後傳遞,那就好像問題 – Rubytastic
好吧然後: