我有以下的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