这是我的onclick功能:
onclick="InboxDetailsPage('<?php echo $message['id']; ?>')
以下是我的参数:threadid
,recipient id
和message id
<input type="hidden" id="threadId-<?php echo $message['id']; ?>" value="<?php echo $message['threadId']; ?>"/>
<input type="hidden" id="recipientId-<?php echo $message['id']; ?>" value="<?php echo $message['otherUserRoleId']; ?>"/>
<?php echo $message['id']; ?>
这是我使用onclick功能的地方:
<div class="inbox">
<?php $inboxno = 0;
foreach ($messageList as $message) { ?>
<?php if ($message['toFromLabel'] == "From") {
$inboxno++; ?>
<input type="hidden" id="threadId-<?php echo $message['id']; ?>" value="<?php echo $message['threadId']; ?>"/>
<input type="hidden" id="recipientId-<?php echo $message['id']; ?>" value="<?php echo $message['otherUserRoleId']; ?>"/>
<tr class="gradeA odd inbox">
<td class="" style="padding-bottom: 1px;" <?php if ($message['status'] == MessageStatusEnum::UNREAD){ ?>style="color:#E55B43;" <?php } else { ?>style="color:#000;" <?php }; ?>><?php echo $message['date']; ?></td>
<td class="" style="padding-bottom: 1px;" <?php if ($message['status'] == MessageStatusEnum::UNREAD){ ?>style="color:#E55B43;" <?php } else { ?>style="color:#000;" <?php }; ?>><?php echo $message['fromName']; ?></td>
<td class=" " style="padding-bottom: 1px;" <?php if ($message['status'] == MessageStatusEnum::UNREAD){ ?>style="color:#E55B43;" <?php } else { ?>style="color:#000;" <?php }; ?> style="width:300px !important"><?php echo $message['subject'] ?></td>
<td class="" style="padding-bottom: 1px;"><a type="button" data-toggle="modal" data-target="#myModalq1" class="btn btn-success " onclick="InboxDetailsPage('<?php echo $message['id']; ?>') ">VIEW</a></td>
</tr>
<?php }
} ?>
</div>
答案 0 :(得分:1)
您可以采用以下格式:
onclick="InboxDetailsPage('<?php echo $message['id'];?>', '<?php echo $message['id'];?>', '<?php echo $message['id'];?>')
或者,只使用一个回音:
onclick="InboxDetailsPage(<?php echo "'{$message['id']}', '{$message['date']}', '{$message['id']}'";?>)
答案 1 :(得分:1)
您可以使用此方法:
<a href="#" onclick="myFunction('parameter1', 'parameter', 'parameter3');">click me</a>
<script>
function myFunction(parameter1, parameter2, parameter3) {
alert(parameter1);
}
</script>
答案 2 :(得分:1)
onclick="InboxDetailsPage(
'<?php echo $message['id'];?>',
'<?php echo $message['id'];?>',
'<?php echo $message['id'];?>'
)
答案 3 :(得分:1)
另一种选择可能是JSON编码选项数组,并发送参数以避免长参数列表,并且首选可读性。
$params=[
'thread_id'=>$message['thread_id'],
'recipient_id'=>$message['recipient_id'],
'id'=>$message['id']
];
<input type="text" onclick="InboxDetailsPage('<?=json_encode($params)?>')">
然后使用它
function InboxDetailsPage(options){
console.log(options.thread_id,options.recipient_id,options.id);
}
答案 4 :(得分:0)
您可以尝试以下操作:
onclick="InboxDetailsPage("<?php echo $message['id'];?>","threadId-<?php echo $message['id']; ?>","recipientId-<?php echo $message['id']; ?>")