我有以下的Javascript和要訪問已經有一個id如何從HTML中的表格數據訪問Javascript變量?
<script type="text/javascript">
function getSelected() {
if(window.getSelection) { return window.getSelection(); }
else if(document.getSelection) { return document.getSelection(); }
else {
var selection = document.selection && document.selection.createRange();
if(selection.text) { return selection.text; }
return false;
}
return false;
}
$(document).ready(function() {
$('#content-area').mouseup(function() {
var selection = getSelected();
if(selection && (selection = new String(selection).replace(/^\s+|\s+$/g,''))) {
alert('Sending the following text to the server via AJAX: ' + selection);
$.ajax({
type: 'post',
url: 'calculate.php',
data: 'selection=' + encodeURI(selection)
});
}
});
});
</script>
我想訪問的地方我的HTML的TD的「選擇」變量「選擇」變量是HTML的TD如下,
<td>
<input type="button" id="optionone" name="optionone" onclick="sendrequest(selection , <?php echo $r ?>);" value="Positive"/>
</td>
我嘗試使用ID(內容區),但沒有幫助。請幫忙。
你想獲得id =「optionone」輸入的值屬性? – Stu
您沒有在您的問題中添加PHP標籤。 – KunJ
Stu:不,我想訪問td中變量「selection」的值,並將其傳遞給'sendrequest'JS函數。幫助 – kmario23