我有一个包含多行的表格。对于每一行,我需要将一个php值$ myvalue传递给onclick里面的java脚本函数myJSfunction,如下所示。我试图通过javascript变量(engenes [thiskey])传递它,但它只保留并传递最后一行的值,因此点击页面时的最后一个值。看起来javascript变量在点击之前无法存储。现在我试图通过DOM元素从表中传递值,因为点击时的值如下所示。但不知何故,DOM元素的值不能作为列表和描述的输入值传递给myJSfunction。谢谢。
php变量$ myvalue和javascript变量thiskey已定义。
<table border="1" cellpadding="10" cellspacing="1" class="tablehead">
<?php foreach ($hg2sl as $key => $myvalue) { ?>
<tr>
<td class="rowB" align="center" valign="top"><p id="mystr"><?php echo $myvalue; ?></p></td>
<td class="rowB" align="center" valign="top"><a onclick="enrich({list: document.getElementById('str4enrich').innerHTML, popup: true, description: document.getElementById('str4enrich').innerHTML });"><script type="text/javascript">document.write(thiskey)</script></a></td>
</tr>
<?php }; ?>
Below is the javascript function
function myJSfunction(options) {
if (typeof options.list === 'undefined') {
alert('No genes defined.');
}
var description = options.description || "",
popup = options.popup || false,
form = document.createElement('form'),
listField = document.createElement('input'),
descField = document.createElement('input');
form.setAttribute('method', 'post');
form.setAttribute('action', 'http://amp.pharm.mssm.edu/Enrichr/enrich');
if (popup) {
form.setAttribute('target', '_blank');
}
form.setAttribute('enctype', 'multipart/form-data');
listField.setAttribute('type', 'hidden');
listField.setAttribute('name', 'list');
listField.setAttribute('value', options.list);
form.appendChild(listField);
descField.setAttribute('type', 'hidden');
descField.setAttribute('name', 'description');
descField.setAttribute('value', description);
form.appendChild(descField);
document.body.appendChild(form);
form.submit();
document.body.removeChild(form);
}